mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 09:23:09 +00:00
config: Make tasks an array
This commit is contained in:
parent
492a15cfb6
commit
c0d44a791b
|
@ -14,7 +14,7 @@ type Config struct {
|
||||||
Title string `toml:"title"`
|
Title string `toml:"title"`
|
||||||
URLs []string `toml:"urls"`
|
URLs []string `toml:"urls"`
|
||||||
Feeds map[string]string `toml:"feeds"`
|
Feeds map[string]string `toml:"feeds"`
|
||||||
Tasks map[string]*Task `toml:"tasks"`
|
Tasks []*Task `toml:"tasks"`
|
||||||
Permalinks map[string]string `toml:"permalinks"`
|
Permalinks map[string]string `toml:"permalinks"`
|
||||||
templates *Templates
|
templates *Templates
|
||||||
}
|
}
|
||||||
|
|
17
main.go
17
main.go
|
@ -42,12 +42,10 @@ func main() {
|
||||||
|
|
||||||
func build() {
|
func build() {
|
||||||
var (
|
var (
|
||||||
task string
|
|
||||||
config string
|
config string
|
||||||
)
|
)
|
||||||
|
|
||||||
flags := flag.NewFlagSet("kiln build", flag.ExitOnError)
|
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.StringVar(&config, "c", "config.toml", "the configuration file to use")
|
||||||
flags.Parse(os.Args[2:])
|
flags.Parse(os.Args[2:])
|
||||||
|
|
||||||
|
@ -67,23 +65,12 @@ func build() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := run(cfg, task); err != nil {
|
if err := run(cfg); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(cfg *Config, taskName string) error {
|
func run(cfg *Config) error {
|
||||||
if taskName == "" {
|
|
||||||
return runAll(cfg)
|
|
||||||
}
|
|
||||||
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 {
|
for _, task := range cfg.Tasks {
|
||||||
err := runTask(cfg, task)
|
err := runTask(cfg, task)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue