// NewUpdateCommand creates a new command for updating rule
NewUpdateCommand creates a new command for updating rule
// NewUpdateCommand creates a new command for updating rule
func NewUpdateCommand(f *factory.Factory) *cobra.Command {
	opts := &options{
		IO:             f.IOStreams,
		Connection:     f.Connection,
		Logger:         f.Logger,
		localizer:      f.Localizer,
		Context:        f.Context,
		ServiceContext: f.ServiceContext,
	}
	cmd := &cobra.Command{
		Use:     "update",
		Short:   f.Localizer.MustLocalize("registry.rule.update.cmd.description.short"),
		Long:    f.Localizer.MustLocalize("registry.rule.update.cmd.description.long"),
		Example: f.Localizer.MustLocalize("registry.rule.update.cmd.example"),
		Args:    cobra.NoArgs,
		RunE: func(cmd *cobra.Command, _ []string) (err error) {
			validator := rulecmdutil.Validator{
				Localizer: opts.localizer,
			}
			err = validator.ValidateRuleType(opts.ruleType)
			if err != nil {
				return err
			}
			isValid, configs := validator.IsValidRuleConfig(opts.ruleType, opts.config)
			if !isValid {
				return opts.localizer.MustLocalizeError("registry.rule.common.error.invalidRuleConfig",
					localize.NewEntry("RuleType", opts.ruleType),
					localize.NewEntry("Config", opts.config),
					localize.NewEntry("ValidConfigList", cmdutil.StringSliceToListStringWithQuotes(configs)),
				)
			}
			registryInstance, err := contextutil.GetCurrentRegistryInstance(f)
			if err != nil {
				return err
			}
			opts.registryID = registryInstance.GetId()
			return runUpdate(opts)
		},
	}
	flags := rulecmdutil.NewFlagSet(cmd, f)
	flags.AddRegistryInstance(&opts.registryID)
	flags.AddArtifactID(&opts.artifactID)
	flags.AddGroup(&opts.group)
	_ = flags.AddConfig(&opts.config).Required()
	_ = flags.AddRuleType(&opts.ruleType).Required()
	return cmd
}
func NewUpdateCommand ( f * factory . Factory ) * cobra . Command { opts := & options { IO : f . IOStreams , Connection : f . Connection , Logger : f . Logger , localizer : f . Localizer , Context : f . Context , ServiceContext : f . ServiceContext , } cmd := & cobra . Command { Use : " " , Short : f . Localizer . MustLocalize ( " " ) , Long : f . Localizer . MustLocalize ( " " ) , Example : f . Localizer . MustLocalize ( " " ) , Args : cobra . NoArgs , RunE : func ( cmd * cobra . Command , _ [ ] string ) ( err error ) { validator := rulecmdutil . Validator { Localizer : opts . localizer , } err = validator . ValidateRuleType ( opts . ruleType ) if err != nil { return err } isValid , configs := validator . IsValidRuleConfig ( opts . ruleType , opts . config ) if ! isValid { return opts . localizer . MustLocalizeError ( " " , localize . NewEntry ( " " , opts . ruleType ) , localize . NewEntry ( " " , opts . config ) , localize . NewEntry ( " " , cmdutil . StringSliceToListStringWithQuotes ( configs ) ) , ) } registryInstance , err := contextutil . GetCurrentRegistryInstance ( f ) if err != nil { return err } opts . registryID = registryInstance . GetId ( ) return runUpdate ( opts ) } , } flags := rulecmdutil . NewFlagSet ( cmd , f ) flags . AddRegistryInstance ( & opts . registryID ) flags . AddArtifactID ( & opts . artifactID ) flags . AddGroup ( & opts . group ) _ = flags . AddConfig ( & opts . config ) . Required ( ) _ = flags . AddRuleType ( & opts . ruleType ) . Required ( ) return cmd }
NewUpdateCommand creates a new command for updating rule
NewUpdateCommand creates a new command for updating rule