create

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "create",
	Short: "Create a new workflow",
	Long:  `Create a new workflow. The workflow must be in YAML format.`,
	Example: fmt.Sprintf(`
cat <<EOF | wfxctl workflow create -
%s
EOF
`, kanbanExample),
	TraverseChildren: true,
	Args:             cobra.OnlyValidArgs,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		return []string{"yaml", "yml"}, cobra.ShellCompDirectiveFilterFileExt
	},
	Run: func(cmd *cobra.Command, args []string) {
		allWorkflows, err := readWorkflows(args, cmd.InOrStdin())
		if err != nil {
			log.Fatal().Err(err).Msg("Failed to read workflows")
		}
		log.Info().Int("count", len(allWorkflows)).Msg("Creating workflows")
		for _, wf := range allWorkflows {
			log.Debug().Msg("Validating workflow")
			if err := wf.Validate(strfmt.Default); err != nil {
				log.Fatal().Msg(err.Error())
			}

			baseCmd := flags.NewBaseCmd()
			client := errutil.Must(baseCmd.CreateHTTPClient())
			params := workflows.NewPostWorkflowsParams().
				WithHTTPClient(client).
				WithWorkflow(wf)

			resp, err := baseCmd.CreateMgmtClient().Workflows.PostWorkflows(params)
			if err != nil {
				errutil.ProcessErrorResponse(cmd.OutOrStderr(), err)
				log.Fatal().Msg("Failed to create workflow")
			}

			log.Info().Str("name", wf.Name).Msg("Created new workflow")
			if err := baseCmd.DumpResponse(cmd.OutOrStdout(), resp.GetPayload()); err != nil {
				log.Fatal().Err(err).Msg("Failed to dump response")
			}
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL