mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-12-04 19:08:22 +01:00
config: Make tasks an array
This commit is contained in:
parent
bfc758430b
commit
ef3d518d9a
@ -14,7 +14,7 @@ type Config struct {
|
||||
Title string `toml:"title"`
|
||||
URLs []string `toml:"urls"`
|
||||
Feeds map[string]string `toml:"feeds"`
|
||||
Tasks map[string]*Task `toml:"tasks"`
|
||||
Tasks []*Task `toml:"tasks"`
|
||||
Permalinks map[string]string `toml:"permalinks"`
|
||||
templates *Templates
|
||||
}
|
||||
|
17
main.go
17
main.go
@ -42,12 +42,10 @@ func main() {
|
||||
|
||||
func build() {
|
||||
var (
|
||||
task string
|
||||
config string
|
||||
)
|
||||
|
||||
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:])
|
||||
|
||||
@ -67,23 +65,12 @@ func build() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := run(cfg, task); err != nil {
|
||||
if err := run(cfg); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(cfg *Config, taskName string) 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 {
|
||||
func run(cfg *Config) error {
|
||||
for _, task := range cfg.Tasks {
|
||||
err := runTask(cfg, task)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user