MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / NewCmdCreate

Function NewCmdCreate

pkg/cmd/runbook/snapshot/create/create.go:86–123  ·  view source on GitHub ↗
(f factory.Factory)

Source from the content-addressed store, hash-verified

84}
85
86func NewCmdCreate(f factory.Factory) *cobra.Command {
87 createFlags := NewCreateFlags()
88
89 cmd := &cobra.Command{
90 Use: "create",
91 Short: "Create a runbook snapshot",
92 Long: "Create a runbook snapshot in Octopus Deploy",
93 Aliases: []string{"new"},
94 Example: heredoc.Docf(`
95 %[1]s runbook snapshot create --project MyProject --runbook "Rebuild DB Indexes"
96 %[1]s runbook snapshot create --project MyProject --runbook "Rebuild DB Indexes" --name "My cool snapshot"
97 %[1]s runbook snapshot create -p MyProject -r "Restart App" --package "azure-cli:1.2.3" --no-prompt
98 %[1]s runbook snapshot create -p MyProject -r "Restart App" --git-resource "Script step from Git:refs/heads/dev-branch" --publish --no-prompt
99 `, constants.ExecutableName),
100 RunE: func(c *cobra.Command, args []string) error {
101 opts := NewCreateOptions(createFlags, cmd.NewDependencies(f, c))
102 outputFormat, err := c.Flags().GetString(constants.FlagOutputFormat)
103 if err != nil {
104 outputFormat = constants.OutputFormatTable
105 }
106
107 return createRun(opts, outputFormat)
108 },
109 }
110
111 flags := cmd.Flags()
112 flags.StringVarP(&createFlags.Project.Value, createFlags.Project.Name, "p", "", "Name or ID of the project where the runbook is")
113 flags.StringVarP(&createFlags.Runbook.Value, createFlags.Runbook.Name, "r", "", "Name or ID of the runbook to create the snapshot for")
114 flags.StringVarP(&createFlags.Name.Value, createFlags.Name.Name, "n", "", "Override the snapshot name")
115 flags.StringVarP(&createFlags.PackageVersion.Value, createFlags.PackageVersion.Name, "", "", "Default version to use for all packages. Only relevant for config-as-code projects where runbooks are stored in Git.")
116 flags.StringArrayVarP(&createFlags.PackageVersionSpec.Value, createFlags.PackageVersionSpec.Name, "", []string{}, "Version specification a specific packages.\nFormat as {package}:{version}, {step}:{version} or {package-ref-name}:{packageOrStep}:{version}\nYou may specify this multiple times")
117 flags.StringVar(&createFlags.SnapshotNotes.Value, createFlags.SnapshotNotes.Name, "", "Release notes to attach")
118 flags.StringVar(&createFlags.SnapshotNotesFile.Value, createFlags.SnapshotNotesFile.Name, "", "Release notes to attach (from file)")
119 flags.BoolVar(&createFlags.Publish.Value, createFlags.Publish.Name, false, "Publish the snapshot immediately")
120 flags.StringArrayVarP(&createFlags.GitResourceRefsSpec.Value, createFlags.GitResourceRefsSpec.Name, "", nil, "Git reference for a specific Git resource.\nFormat as {step}:{git-ref}, {step}:{git-resource-name}:{git-ref}\nYou may specify this multiple times.\nOnly relevant for config-as-code projects where runbooks are stored in Git.")
121
122 return cmd
123}
124
125func createRun(opts *CreateOptions, outputFormat string) error {
126 if opts.SnapshotNotes.Value != "" && opts.SnapshotNotesFile.Value != "" {

Callers

nothing calls this directly

Calls 3

NewCreateFlagsFunction · 0.70
NewCreateOptionsFunction · 0.70
createRunFunction · 0.70

Tested by

no test coverage detected