Skip to content

Commit c598b72

Browse files
fix generate playbook arg
1 parent b5856ec commit c598b72

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

cmd/cmd.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,18 @@ func GetDaemonClient() (*daemon.Client, error) {
279279
var generateCmd = &cobra.Command{
280280
Use: "generate",
281281
Short: "Generate a graph from a playbook and save it as Go code",
282+
Args: cobra.RangeArgs(0, 1),
282283
RunE: func(cmd *cobra.Command, args []string) error {
284+
// Accept playbook as positional argument (preferred), fallback to --playbook flag
285+
if playbookFile == "" {
286+
if len(args) >= 1 {
287+
playbookFile = args[0]
288+
}
289+
}
290+
if playbookFile == "" {
291+
return fmt.Errorf("playbook file is required; provide it as a positional argument (spage run playbook.yaml) or with --playbook")
292+
}
293+
283294
// Resolve bundle references using FS (no disk extraction)
284295
var cleanup func()
285296
var graph pkg.Graph
@@ -660,10 +671,6 @@ func init() {
660671
generateCmd.Flags().StringSliceVar(&skipTags, "skip-tags", []string{}, "Skip tasks with these tags (comma-separated)")
661672
generateCmd.Flags().BoolVar(&becomeMode, "become", false, "Run all tasks with become: true and become_user: root")
662673

663-
if err := generateCmd.MarkFlagRequired("playbook"); err != nil {
664-
panic(fmt.Sprintf("failed to mark playbook flag as required: %v", err))
665-
}
666-
667674
runCmd.Flags().StringVarP(&playbookFile, "playbook", "p", "", "Playbook file")
668675
runCmd.Flags().StringVarP(&inventoryFile, "inventory", "i", "", "Inventory file (default: localhost)")
669676
runCmd.Flags().StringVarP(&outputFile, "output", "o", "generated_tasks.go", "Output file (default: generated_tasks.go)")

0 commit comments

Comments
 (0)