Skip to content

Commit

Permalink
feat: add option to set archive files name
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeceM committed Aug 26, 2022
1 parent 003d4ce commit 60056af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
21 changes: 12 additions & 9 deletions config/init.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package config

import (
"flag"
"log"

"github.com/BurntSushi/toml"
)

type bundler struct {
IgnoreFile string `toml:"ignore_file"`
SourceDir string `toml:"source_dir"`
IgnoreFile string `toml:"ignore_file"` // the .distignore file that should be used
SourceDir string `toml:"source_dir"` // the input directory that has the plugin
}

type TomlConfig struct {
APIAddr string `toml:"api_addr"`
Bundler bundler `toml:"bundler"`
Name string `toml:"name"` // this is the plugin / theme name
Bundler bundler `toml:"bundler"` // the bundler options
Verbose bool
}

Expand All @@ -23,19 +22,23 @@ var (
configPath string
)

type ConfigOptions struct {
ConfigPath string
Verbose bool
}

func loadConfig() {

if _, err := toml.DecodeFile(configPath, &Config); err != nil {
log.Fatalln("Reading config failed", err)
}
}

func Init() {
func Init(options ConfigOptions) {
// Path to config file can be passed in.
flag.StringVar(&configPath, "config", "config.toml", "Path to config file")
Config.Verbose = *flag.Bool("vv", false, "Get Verbose")

flag.Parse()
configPath = options.ConfigPath
Config.Verbose = options.Verbose

loadConfig()
}
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
package main

import (
"flag"
"log"
"wp-bundler/config"
"wp-bundler/zipper"
)

var (
configPath string
verbose bool
)

func main() {
config.Init()
flag.StringVar(&configPath, "config", "config.toml", "Path to config file")
flag.BoolVar(&verbose, "vv", false, "Get Verbose")

flag.Parse()

config.Init(config.ConfigOptions{
ConfigPath: configPath,
Verbose: verbose,
})

zipper.Init(config.Config)

log.Println("Application is using source dir:", config.Config.Bundler.SourceDir)
Expand Down
3 changes: 2 additions & 1 deletion zipper/zipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (m *Zipper) Write(dir string) {
// This snippet happens to work because I don't use
// absolute paths, but ensure your real-world code
// transforms path into a zip-root relative path.
// f, err := m.Writer.Create(fmt.Sprintf("%s/%s", config.Config.Name, path))
f, err := m.Writer.Create(path)
if err != nil {
return err
Expand All @@ -86,7 +87,7 @@ func (m *Zipper) Write(dir string) {

func (m *Zipper) create() {
fmt.Println("Opening archive")
archive, err := os.Create("archive.zip")
archive, err := os.Create(fmt.Sprintf("%s.zip", config.Config.Name))
m.Archive = *archive

if err != nil {
Expand Down

0 comments on commit 60056af

Please sign in to comment.