From 133b371e4cc22fa73e591a1713f00e14a167f1b9 Mon Sep 17 00:00:00 2001 From: adnano Date: Tue, 20 Apr 2021 16:12:52 -0400 Subject: [PATCH] Fix build flag parsing --- doc/kiln.1.scd | 2 +- main.go | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/doc/kiln.1.scd b/doc/kiln.1.scd index 1434f58..144e2f8 100644 --- a/doc/kiln.1.scd +++ b/doc/kiln.1.scd @@ -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 diff --git a/main.go b/main.go index 1772936..91a1a6c 100644 --- a/main.go +++ b/main.go @@ -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,16 +65,14 @@ 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) } + 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 {