Fix build flag parsing

This commit is contained in:
adnano 2021-04-20 16:12:52 -04:00
parent 0109a33b11
commit 133b371e4c
2 changed files with 11 additions and 12 deletions

View file

@ -30,7 +30,7 @@ kiln - a simple static site generator
Specifies the configuration file to use. Defaults to "config.toml".
*-t* _task_
Specifies the task to run. Defaults to "all", which runs all tasks.
Specifies the task to run. If unspecified, all tasks will be run.
# OVERVIEW

13
main.go
View file

@ -45,9 +45,10 @@ func build() {
config string
)
flag.StringVar(&task, "t", "all", "the task to run")
flag.StringVar(&config, "c", "config.toml", "the configuration file to use")
flag.Parse()
flags := flag.NewFlagSet("kiln build", flag.ExitOnError)
flags.StringVar(&task, "t", "", "the task to run")
flags.StringVar(&config, "c", "config.toml", "the configuration file to use")
flags.Parse(os.Args[2:])
// Load config
cfg, err := LoadConfig(config)
@ -64,17 +65,15 @@ func build() {
}
func run(cfg *Config, taskName string) error {
switch taskName {
case "all":
if taskName == "" {
return runAll(cfg)
default:
}
task, ok := cfg.Tasks[taskName]
if !ok {
return fmt.Errorf("run task %q: no such task", taskName)
}
return runTask(cfg, task)
}
}
func runAll(cfg *Config) error {
for _, task := range cfg.Tasks {