1
0
mirror of https://git.sr.ht/~adnano/kiln synced 2024-11-08 10:09:18 +01:00

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

@ -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

21
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 {