53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/spf13/cobra"
|
||
|
"os"
|
||
|
commands "runner/internal/commands"
|
||
|
)
|
||
|
|
||
|
var cli = &cobra.Command{
|
||
|
Use: "runner",
|
||
|
}
|
||
|
|
||
|
var execute = &cobra.Command{
|
||
|
Use: "execute [workflow-file]",
|
||
|
Short: "Executes the provided workflow.",
|
||
|
Args: cobra.MinimumNArgs(1),
|
||
|
Run: func(cmd *cobra.Command, args []string) {
|
||
|
configPath, _ := cmd.Flags().GetString("config")
|
||
|
|
||
|
if err := commands.ExecuteWorkflow(configPath, args[0]); err != nil {
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
},
|
||
|
}
|
||
|
|
||
|
var validate = &cobra.Command{
|
||
|
Use: "validate [workflow-file]",
|
||
|
Short: "Validates the structure of the provided workflow.",
|
||
|
Args: cobra.MinimumNArgs(1),
|
||
|
Run: func(cmd *cobra.Command, args []string) {
|
||
|
configPath, _ := cmd.Flags().GetString("config")
|
||
|
|
||
|
if err := commands.ValidateWorkflow(configPath, args[0]); err != nil {
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
},
|
||
|
}
|
||
|
|
||
|
var knownCommands = []*cobra.Command{
|
||
|
execute,
|
||
|
validate,
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
cli.PersistentFlags().StringP("config", "c", "./config.yml", "Declarative runner configuration.")
|
||
|
|
||
|
for _, command := range knownCommands {
|
||
|
cli.AddCommand(command)
|
||
|
}
|
||
|
|
||
|
cli.Execute()
|
||
|
}
|