MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / newPolicyDevelopInitCmd

Function newPolicyDevelopInitCmd

app/cli/cmd/policy_develop_init.go:25–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23)
24
25func newPolicyDevelopInitCmd() *cobra.Command {
26 var (
27 force bool
28 embedded bool
29 name string
30 description string
31 directory string
32 )
33
34 cmd := &cobra.Command{
35 Use: "init",
36 Short: "Initialize a new policy",
37 Long: `Initialize a new policy by creating template policy files in the specified directory.
38By default, it creates chainloop-policy.yaml and chainloop-policy.rego files.`,
39 Example: `
40 # Initialize in current directory with separate files
41 chainloop policy develop init
42
43 # Initialize in specific directory with embedded format and policy name
44 chainloop policy develop init --directory ./policies --embedded --name mypolicy`,
45 RunE: func(_ *cobra.Command, _ []string) error {
46 if directory == "" {
47 directory = "."
48 }
49 opts := &action.PolicyInitOpts{
50 Force: force,
51 Embedded: embedded,
52 Name: name,
53 Description: description,
54 Directory: directory,
55 }
56
57 policyInit, err := action.NewPolicyInit(opts, ActionOpts)
58 if err != nil {
59 return fmt.Errorf("failed to initialize policy: %w", err)
60 }
61
62 if err := policyInit.Run(); err != nil {
63 return newGracefulError(err)
64 }
65
66 logger.Info().Msg("Initialized policy files")
67
68 return nil
69 },
70 }
71
72 cmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite existing files")
73 cmd.Flags().BoolVar(&embedded, "embedded", false, "initialize an embedded policy (single YAML file)")
74 cmd.Flags().StringVar(&name, "name", "", "name of the policy")
75 cmd.Flags().StringVar(&description, "description", "", "description of the policy")
76 cmd.Flags().StringVar(&directory, "directory", "", "directory for policy")
77 return cmd
78}

Callers 1

newPolicyDevelopCmdFunction · 0.85

Calls 4

RunMethod · 0.95
NewPolicyInitFunction · 0.92
newGracefulErrorFunction · 0.85
InfoMethod · 0.65

Tested by

no test coverage detected