mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
Fix build flag parsing
This commit is contained in:
parent
0109a33b11
commit
133b371e4c
|
@ -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
13
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,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 {
|
||||
|
|
Loading…
Reference in a new issue