diff --git a/internal/command/box/box.go b/internal/command/box/box.go index 0887b055..d8710037 100644 --- a/internal/command/box/box.go +++ b/internal/command/box/box.go @@ -16,11 +16,11 @@ import ( ) type boxCmdOptions struct { - configRef *config.ConfigRef - sourceFlag *commonFlag.SourceFlag - providerFlag *commonFlag.ProviderFlag - provider boxModel.BoxProvider - tunnelFlag *boxFlag.TunnelFlag + configRef *config.ConfigRef + templateSourceFlag *commonFlag.TemplateSourceFlag + providerFlag *commonFlag.ProviderFlag + provider boxModel.BoxProvider + tunnelFlag *boxFlag.TunnelFlag } func NewBoxCmd(configRef *config.ConfigRef) *cobra.Command { @@ -76,7 +76,7 @@ func NewBoxCmd(configRef *config.ConfigRef) *cobra.Command { } // --revision or --local - opts.sourceFlag = commonFlag.AddSourceFlag(command) + opts.templateSourceFlag = commonFlag.AddTemplateSourceFlag(command) // --provider (enum) opts.providerFlag = boxFlag.AddBoxProviderFlag(command) // --no-exec or --no-tunnel @@ -99,12 +99,12 @@ func (opts *boxCmdOptions) validate(cmd *cobra.Command, args []string) error { } opts.provider = validProvider - if err := commonFlag.ValidateSourceFlag(opts.providerFlag, opts.sourceFlag); err != nil { + if err := commonFlag.ValidateTemplateSourceFlag(opts.providerFlag, opts.templateSourceFlag); err != nil { log.Warn().Err(err).Msgf(commonFlag.ErrorFlagNotSupported) return errors.New(commonFlag.ErrorFlagNotSupported) } - if err := boxFlag.ValidateTunnelFlag(opts.provider, opts.tunnelFlag); err != nil { + if err := boxFlag.ValidateTunnelFlag(opts.tunnelFlag, opts.provider); err != nil { log.Warn().Err(err).Msgf("ignore validation %s", commonFlag.ErrorFlagNotSupported) // ignore validation return nil @@ -114,7 +114,7 @@ func (opts *boxCmdOptions) validate(cmd *cobra.Command, args []string) error { func (opts *boxCmdOptions) run(cmd *cobra.Command, args []string) error { - if opts.sourceFlag.Local { + if opts.templateSourceFlag.Local { path := args[0] log.Debug().Msgf("temporary box from local template: path=%s", path) @@ -123,9 +123,9 @@ func (opts *boxCmdOptions) run(cmd *cobra.Command, args []string) error { } else { name := args[0] - log.Debug().Msgf("temporary box from git template: name=%s revision=%s", name, opts.sourceFlag.Revision) + log.Debug().Msgf("temporary box from git template: name=%s revision=%s", name, opts.templateSourceFlag.Revision) - sourceOpts := commonCmd.NewGitSourceOptions(opts.configRef.Config.Template.CacheDir, opts.sourceFlag.Revision) + sourceOpts := commonCmd.NewGitSourceOptions(opts.configRef.Config.Template.CacheDir, opts.templateSourceFlag.Revision) sourceLoader := template.NewGitLoader[boxModel.BoxV1](sourceOpts, name) labels := boxModel.NewBoxLabels().AddDefaultGit(sourceOpts.RepositoryUrl, sourceOpts.DefaultRevision, sourceOpts.CacheDirName()) return opts.temporaryBox(sourceLoader, labels) diff --git a/internal/command/box/flag/tunnel.go b/internal/command/box/flag/tunnel.go index c08e34e6..92cfa80c 100644 --- a/internal/command/box/flag/tunnel.go +++ b/internal/command/box/flag/tunnel.go @@ -1,6 +1,8 @@ package flag import ( + "fmt" + "github.com/spf13/cobra" commonFlag "github.com/hckops/hckctl/internal/command/common/flag" @@ -52,3 +54,15 @@ func AddTunnelFlag(command *cobra.Command) *TunnelFlag { command.MarkFlagsMutuallyExclusive(noExecFlag, noTunnelFlag) return tunnelFlag } + +func ValidateTunnelFlag(tunnelFlag *TunnelFlag, provider boxModel.BoxProvider) error { + switch provider { + // docker exposes automatically all ports + case boxModel.Docker: + if tunnelFlag.NoExec || tunnelFlag.NoTunnel { + return fmt.Errorf("flag not supported: provider=%s %s=%v %s=%v", + boxModel.Docker.String(), noExecFlagName, tunnelFlag.NoExec, noTunnelFlagName, tunnelFlag.NoTunnel) + } + } + return nil +} diff --git a/internal/command/box/flag/validation_test.go b/internal/command/box/flag/tunnel_test.go similarity index 63% rename from internal/command/box/flag/validation_test.go rename to internal/command/box/flag/tunnel_test.go index d0ba8859..72e7da58 100644 --- a/internal/command/box/flag/validation_test.go +++ b/internal/command/box/flag/tunnel_test.go @@ -9,12 +9,12 @@ import ( ) func TestValidateTunnelFlag(t *testing.T) { - err := ValidateTunnelFlag(model.Docker, &TunnelFlag{NoExec: true, NoTunnel: true}) + err := ValidateTunnelFlag(&TunnelFlag{NoExec: true, NoTunnel: true}, model.Docker) assert.EqualError(t, err, "flag not supported: provider=docker no-exec=true no-tunnel=true") - errExec := ValidateTunnelFlag(model.Docker, &TunnelFlag{NoExec: true, NoTunnel: false}) + errExec := ValidateTunnelFlag(&TunnelFlag{NoExec: true, NoTunnel: false}, model.Docker) assert.EqualError(t, errExec, "flag not supported: provider=docker no-exec=true no-tunnel=false") - errTunnel := ValidateTunnelFlag(model.Docker, &TunnelFlag{NoExec: false, NoTunnel: true}) + errTunnel := ValidateTunnelFlag(&TunnelFlag{NoExec: false, NoTunnel: true}, model.Docker) assert.EqualError(t, errTunnel, "flag not supported: provider=docker no-exec=false no-tunnel=true") } diff --git a/internal/command/box/flag/validation.go b/internal/command/box/flag/validation.go deleted file mode 100644 index c2ebc040..00000000 --- a/internal/command/box/flag/validation.go +++ /dev/null @@ -1,19 +0,0 @@ -package flag - -import ( - "fmt" - - "github.com/hckops/hckctl/pkg/box/model" -) - -func ValidateTunnelFlag(provider model.BoxProvider, tunnelFlag *TunnelFlag) error { - switch provider { - // docker exposes automatically all ports - case model.Docker: - if tunnelFlag.NoExec || tunnelFlag.NoTunnel { - return fmt.Errorf("flag not supported: provider=%s %s=%v %s=%v", - model.Docker.String(), noExecFlagName, tunnelFlag.NoExec, noTunnelFlagName, tunnelFlag.NoTunnel) - } - } - return nil -} diff --git a/internal/command/box/open.go b/internal/command/box/open.go index 78ec517d..313e0863 100644 --- a/internal/command/box/open.go +++ b/internal/command/box/open.go @@ -41,7 +41,7 @@ func (opts *boxOpenCmdOptions) run(cmd *cobra.Command, args []string) error { connectClient := func(invokeOpts *invokeOptions, _ *model.BoxDetails) error { // log only and ignore invalid tunnel flags to avoid false positive during provider attempts - if err := boxFlag.ValidateTunnelFlag(invokeOpts.client.Provider(), opts.tunnelFlag); err != nil { + if err := boxFlag.ValidateTunnelFlag(opts.tunnelFlag, invokeOpts.client.Provider()); err != nil { log.Warn().Err(err).Msgf("ignore validation %s", commonFlag.ErrorFlagNotSupported) } diff --git a/internal/command/box/start.go b/internal/command/box/start.go index bd0f306c..f693ef5c 100644 --- a/internal/command/box/start.go +++ b/internal/command/box/start.go @@ -17,10 +17,10 @@ import ( ) type boxStartCmdOptions struct { - configRef *config.ConfigRef - sourceFlag *commonFlag.SourceFlag - providerFlag *commonFlag.ProviderFlag - provider boxModel.BoxProvider + configRef *config.ConfigRef + templateSourceFlag *commonFlag.TemplateSourceFlag + providerFlag *commonFlag.ProviderFlag + provider boxModel.BoxProvider } func NewBoxStartCmd(configRef *config.ConfigRef) *cobra.Command { @@ -38,7 +38,7 @@ func NewBoxStartCmd(configRef *config.ConfigRef) *cobra.Command { } // --revision or --local - opts.sourceFlag = commonFlag.AddSourceFlag(command) + opts.templateSourceFlag = commonFlag.AddTemplateSourceFlag(command) // --provider (enum) opts.providerFlag = boxFlag.AddBoxProviderFlag(command) @@ -53,7 +53,7 @@ func (opts *boxStartCmdOptions) validate(cmd *cobra.Command, args []string) erro } opts.provider = validProvider - if err := commonFlag.ValidateSourceFlag(opts.providerFlag, opts.sourceFlag); err != nil { + if err := commonFlag.ValidateTemplateSourceFlag(opts.providerFlag, opts.templateSourceFlag); err != nil { log.Warn().Err(err).Msgf(commonFlag.ErrorFlagNotSupported) return errors.New(commonFlag.ErrorFlagNotSupported) } @@ -62,7 +62,7 @@ func (opts *boxStartCmdOptions) validate(cmd *cobra.Command, args []string) erro func (opts *boxStartCmdOptions) run(cmd *cobra.Command, args []string) error { - if opts.sourceFlag.Local { + if opts.templateSourceFlag.Local { path := args[0] log.Debug().Msgf("start box from local template: path=%s", path) @@ -71,9 +71,9 @@ func (opts *boxStartCmdOptions) run(cmd *cobra.Command, args []string) error { } else { name := args[0] - log.Debug().Msgf("start box from git template: name=%s revision=%s", name, opts.sourceFlag.Revision) + log.Debug().Msgf("start box from git template: name=%s revision=%s", name, opts.templateSourceFlag.Revision) - sourceOpts := commonCmd.NewGitSourceOptions(opts.configRef.Config.Template.CacheDir, opts.sourceFlag.Revision) + sourceOpts := commonCmd.NewGitSourceOptions(opts.configRef.Config.Template.CacheDir, opts.templateSourceFlag.Revision) sourceLoader := template.NewGitLoader[boxModel.BoxV1](sourceOpts, name) labels := boxModel.NewBoxLabels().AddDefaultGit(sourceOpts.RepositoryUrl, sourceOpts.DefaultRevision, sourceOpts.CacheDirName()) return opts.startBox(sourceLoader, labels) diff --git a/internal/command/common/flag/network.go b/internal/command/common/flag/network.go index f018cf77..24c83489 100644 --- a/internal/command/common/flag/network.go +++ b/internal/command/common/flag/network.go @@ -1,7 +1,12 @@ package flag import ( + "fmt" + "strings" + "github.com/spf13/cobra" + + "github.com/hckops/hckctl/pkg/common/model" ) func AddNetworkVpnFlag(command *cobra.Command, networkVpn *string) string { @@ -12,3 +17,13 @@ func AddNetworkVpnFlag(command *cobra.Command, networkVpn *string) string { command.Flags().StringVarP(networkVpn, flagName, NoneFlagShortHand, "", flagUsage) return flagName } + +func ValidateNetworkVpnFlag(name string, networks map[string]model.VpnNetworkInfo) error { + if strings.TrimSpace(name) == "" { + return nil + } + if _, ok := networks[name]; ok { + return nil + } + return fmt.Errorf("vpn network [%s] config not found", name) +} diff --git a/internal/command/common/flag/validation_test.go b/internal/command/common/flag/network_test.go similarity index 54% rename from internal/command/common/flag/validation_test.go rename to internal/command/common/flag/network_test.go index 3f3e5943..a502a760 100644 --- a/internal/command/common/flag/validation_test.go +++ b/internal/command/common/flag/network_test.go @@ -8,16 +8,6 @@ import ( "github.com/hckops/hckctl/pkg/common/model" ) -func TestValidateSourceFlag(t *testing.T) { - provider := CloudProviderFlag - - errRevision := ValidateSourceFlag(&provider, &SourceFlag{Revision: "invalid"}) - assert.EqualError(t, errRevision, "flag not supported: provider=cloud revision=invalid") - - errLocal := ValidateSourceFlag(&provider, &SourceFlag{Revision: "main", Local: true}) - assert.EqualError(t, errLocal, "flag not supported: provider=cloud local=true") -} - func TestValidateNetworkVpnFlag(t *testing.T) { assert.Nil(t, ValidateNetworkVpnFlag("", map[string]model.VpnNetworkInfo{})) assert.Nil(t, ValidateNetworkVpnFlag("default", map[string]model.VpnNetworkInfo{"default": {}})) diff --git a/internal/command/common/flag/template.go b/internal/command/common/flag/template.go index 7bafa3cc..65a0bb73 100644 --- a/internal/command/common/flag/template.go +++ b/internal/command/common/flag/template.go @@ -10,32 +10,31 @@ import ( ) const ( - RevisionFlagName = "revision" + revisionFlagName = "revision" LocalFlagName = "local" OfflineFlagName = "offline" ) -// TODO add remote - -type SourceFlag struct { +type TemplateSourceFlag struct { Revision string Local bool + // TODO add remote } -func AddRevisionFlag(command *cobra.Command, revision *string) string { +func AddTemplateRevisionFlag(command *cobra.Command, revision *string) string { const ( flagShortName = "r" flagUsage = "megalopolis version, one of branch|tag|sha" ) - command.Flags().StringVarP(revision, RevisionFlagName, flagShortName, common.TemplateSourceRevision, flagUsage) + command.Flags().StringVarP(revision, revisionFlagName, flagShortName, common.TemplateSourceRevision, flagUsage) // overrides default template val - _ = viper.BindPFlag(fmt.Sprintf("template.%s", RevisionFlagName), command.Flags().Lookup(RevisionFlagName)) + _ = viper.BindPFlag(fmt.Sprintf("template.%s", revisionFlagName), command.Flags().Lookup(revisionFlagName)) - return RevisionFlagName + return revisionFlagName } -func AddLocalFlag(command *cobra.Command, local *bool) string { +func AddTemplateLocalFlag(command *cobra.Command, local *bool) string { const ( flagUsage = "use a local template" ) @@ -43,18 +42,34 @@ func AddLocalFlag(command *cobra.Command, local *bool) string { return LocalFlagName } -func AddSourceFlag(command *cobra.Command) *SourceFlag { - sourceFlag := &SourceFlag{} - revisionFlag := AddRevisionFlag(command, &sourceFlag.Revision) - localFlag := AddLocalFlag(command, &sourceFlag.Local) - command.MarkFlagsMutuallyExclusive(revisionFlag, localFlag) - return sourceFlag -} - -func AddOfflineFlag(command *cobra.Command, offline *bool) string { +func AddTemplateOfflineFlag(command *cobra.Command, offline *bool) string { const ( flagUsage = "ignore latest git templates" ) command.Flags().BoolVarP(offline, OfflineFlagName, NoneFlagShortHand, false, flagUsage) return OfflineFlagName } + +func AddTemplateSourceFlag(command *cobra.Command) *TemplateSourceFlag { + sourceFlag := &TemplateSourceFlag{} + revisionFlag := AddTemplateRevisionFlag(command, &sourceFlag.Revision) + localFlag := AddTemplateLocalFlag(command, &sourceFlag.Local) + command.MarkFlagsMutuallyExclusive(revisionFlag, localFlag) + return sourceFlag +} + +func ValidateTemplateSourceFlag(provider *ProviderFlag, sourceFlag *TemplateSourceFlag) error { + switch *provider { + // clients can't decide revision or deploy custom templates + case CloudProviderFlag: + if sourceFlag.Revision != common.TemplateSourceRevision { + return fmt.Errorf("flag not supported: provider=%s %s=%s", + provider.String(), revisionFlagName, sourceFlag.Revision) + } + if sourceFlag.Local { + return fmt.Errorf("flag not supported: provider=%s %s=%v", + provider.String(), LocalFlagName, sourceFlag.Local) + } + } + return nil +} diff --git a/internal/command/common/flag/template_test.go b/internal/command/common/flag/template_test.go new file mode 100644 index 00000000..f4b0bd00 --- /dev/null +++ b/internal/command/common/flag/template_test.go @@ -0,0 +1,17 @@ +package flag + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestValidateTemplateSourceFlag(t *testing.T) { + provider := CloudProviderFlag + + errRevision := ValidateTemplateSourceFlag(&provider, &TemplateSourceFlag{Revision: "invalid"}) + assert.EqualError(t, errRevision, "flag not supported: provider=cloud revision=invalid") + + errLocal := ValidateTemplateSourceFlag(&provider, &TemplateSourceFlag{Revision: "main", Local: true}) + assert.EqualError(t, errLocal, "flag not supported: provider=cloud local=true") +} diff --git a/internal/command/common/flag/validation.go b/internal/command/common/flag/validation.go deleted file mode 100644 index 85c66f09..00000000 --- a/internal/command/common/flag/validation.go +++ /dev/null @@ -1,35 +0,0 @@ -package flag - -import ( - "fmt" - "strings" - - "github.com/hckops/hckctl/internal/command/common" - "github.com/hckops/hckctl/pkg/common/model" -) - -func ValidateSourceFlag(provider *ProviderFlag, sourceFlag *SourceFlag) error { - switch *provider { - // clients can't decide revision or deploy custom templates - case CloudProviderFlag: - if sourceFlag.Revision != common.TemplateSourceRevision { - return fmt.Errorf("flag not supported: provider=%s %s=%s", - provider.String(), RevisionFlagName, sourceFlag.Revision) - } - if sourceFlag.Local { - return fmt.Errorf("flag not supported: provider=%s %s=%v", - provider.String(), LocalFlagName, sourceFlag.Local) - } - } - return nil -} - -func ValidateNetworkVpnFlag(name string, networks map[string]model.VpnNetworkInfo) error { - if strings.TrimSpace(name) == "" { - return nil - } - if _, ok := networks[name]; ok { - return nil - } - return fmt.Errorf("vpn network [%s] config not found", name) -} diff --git a/internal/command/lab/lab.go b/internal/command/lab/lab.go index 9c6912db..039afca6 100644 --- a/internal/command/lab/lab.go +++ b/internal/command/lab/lab.go @@ -21,10 +21,10 @@ import ( ) type labCmdOptions struct { - configRef *config.ConfigRef - sourceFlag *commonFlag.SourceFlag - providerFlag *commonFlag.ProviderFlag - provider labModel.LabProvider + configRef *config.ConfigRef + templateSourceFlag *commonFlag.TemplateSourceFlag + providerFlag *commonFlag.ProviderFlag + provider labModel.LabProvider } func NewLabCmd(configRef *config.ConfigRef) *cobra.Command { @@ -43,7 +43,7 @@ func NewLabCmd(configRef *config.ConfigRef) *cobra.Command { } // --revision or --local - opts.sourceFlag = commonFlag.AddSourceFlag(command) + opts.templateSourceFlag = commonFlag.AddTemplateSourceFlag(command) // --provider (enum) opts.providerFlag = labFlag.AddLabProviderFlag(command) @@ -58,7 +58,7 @@ func (opts *labCmdOptions) validate(cmd *cobra.Command, args []string) error { } opts.provider = validProvider - if err := commonFlag.ValidateSourceFlag(opts.providerFlag, opts.sourceFlag); err != nil { + if err := commonFlag.ValidateTemplateSourceFlag(opts.providerFlag, opts.templateSourceFlag); err != nil { log.Warn().Err(err).Msgf(commonFlag.ErrorFlagNotSupported) return errors.New(commonFlag.ErrorFlagNotSupported) } @@ -67,7 +67,7 @@ func (opts *labCmdOptions) validate(cmd *cobra.Command, args []string) error { func (opts *labCmdOptions) run(cmd *cobra.Command, args []string) error { - if opts.sourceFlag.Local { + if opts.templateSourceFlag.Local { path := args[0] log.Debug().Msgf("create lab from local template: path=%s", path) @@ -76,9 +76,9 @@ func (opts *labCmdOptions) run(cmd *cobra.Command, args []string) error { } else { name := args[0] - log.Debug().Msgf("create lab from git template: name=%s revision=%s", name, opts.sourceFlag.Revision) + log.Debug().Msgf("create lab from git template: name=%s revision=%s", name, opts.templateSourceFlag.Revision) - sourceOpts := commonCmd.NewGitSourceOptions(opts.configRef.Config.Template.CacheDir, opts.sourceFlag.Revision) + sourceOpts := commonCmd.NewGitSourceOptions(opts.configRef.Config.Template.CacheDir, opts.templateSourceFlag.Revision) sourceLoader := template.NewGitLoader[labModel.LabV1](sourceOpts, name) labels := labModel.NewLabLabels().AddDefaultGit(sourceOpts.RepositoryUrl, sourceOpts.DefaultRevision, sourceOpts.CacheDirName()) return startLab(sourceLoader, opts.provider, opts.configRef, labels) diff --git a/internal/command/task/task.go b/internal/command/task/task.go index 4351d3cf..103b419b 100644 --- a/internal/command/task/task.go +++ b/internal/command/task/task.go @@ -21,7 +21,7 @@ import ( type taskCmdOptions struct { configRef *config.ConfigRef - sourceFlag *commonFlag.SourceFlag + sourceFlag *commonFlag.TemplateSourceFlag providerFlag *commonFlag.ProviderFlag provider taskModel.TaskProvider commandFlag *taskFlag.CommandFlag @@ -45,12 +45,12 @@ func NewTaskCmd(configRef *config.ConfigRef) *cobra.Command { } // --revision or --local - opts.sourceFlag = commonFlag.AddSourceFlag(command) + opts.sourceFlag = commonFlag.AddTemplateSourceFlag(command) // --provider (enum) opts.providerFlag = taskFlag.AddTaskProviderFlag(command) // --network-vpn commonFlag.AddNetworkVpnFlag(command, &opts.networkVpnFlag) - // --inline OR --command with N --inputs + // --inline or --command with N --inputs opts.commandFlag = taskFlag.AddCommandFlag(command) return command @@ -66,7 +66,7 @@ func (opts *taskCmdOptions) validate(cmd *cobra.Command, args []string) error { opts.provider = validProvider // source - if err := commonFlag.ValidateSourceFlag(opts.providerFlag, opts.sourceFlag); err != nil { + if err := commonFlag.ValidateTemplateSourceFlag(opts.providerFlag, opts.sourceFlag); err != nil { log.Warn().Err(err).Msgf(commonFlag.ErrorFlagNotSupported) return errors.New(commonFlag.ErrorFlagNotSupported) } @@ -76,6 +76,8 @@ func (opts *taskCmdOptions) validate(cmd *cobra.Command, args []string) error { return err } + // TODO validate --inputs key=value format + return nil } diff --git a/internal/command/template/list.go b/internal/command/template/list.go index 907637fa..7effd39f 100644 --- a/internal/command/template/list.go +++ b/internal/command/template/list.go @@ -49,9 +49,9 @@ func NewTemplateListCmd(configRef *config.ConfigRef) *cobra.Command { } // --revision - flag.AddRevisionFlag(command, &opts.revisionFlag) + flag.AddTemplateRevisionFlag(command, &opts.revisionFlag) // --offline - flag.AddOfflineFlag(command, &opts.offlineFlag) + flag.AddTemplateOfflineFlag(command, &opts.offlineFlag) return command } diff --git a/internal/command/template/template.go b/internal/command/template/template.go index 51a9ddb6..5efb4509 100644 --- a/internal/command/template/template.go +++ b/internal/command/template/template.go @@ -17,10 +17,10 @@ import ( ) type templateCmdOptions struct { - configRef *config.ConfigRef - formatFlag formatFlag - sourceFlag *flag.SourceFlag - offlineFlag bool + configRef *config.ConfigRef + formatFlag formatFlag + templateSourceFlag *flag.TemplateSourceFlag + offlineFlag bool } func NewTemplateCmd(configRef *config.ConfigRef) *cobra.Command { @@ -65,10 +65,9 @@ func NewTemplateCmd(configRef *config.ConfigRef) *cobra.Command { command.Flags().Var(formatValue, formatFlagName, formatUsage) // --revision or --local - opts.sourceFlag = flag.AddSourceFlag(command) - + opts.templateSourceFlag = flag.AddTemplateSourceFlag(command) // --offline or --local - flag.AddOfflineFlag(command, &opts.offlineFlag) + flag.AddTemplateOfflineFlag(command, &opts.offlineFlag) command.MarkFlagsMutuallyExclusive(flag.OfflineFlagName, flag.LocalFlagName) command.AddCommand(NewTemplateListCmd(configRef)) @@ -81,7 +80,7 @@ func (opts *templateCmdOptions) run(cmd *cobra.Command, args []string) error { format := opts.formatFlag.String() // TODO add remote url - if opts.sourceFlag.Local { + if opts.templateSourceFlag.Local { path := args[0] log.Debug().Msgf("print local template: path=%s", path) @@ -92,10 +91,10 @@ func (opts *templateCmdOptions) run(cmd *cobra.Command, args []string) error { CacheBaseDir: opts.configRef.Config.Template.CacheDir, RepositoryUrl: common.TemplateSourceUrl, DefaultRevision: common.TemplateSourceRevision, - Revision: opts.sourceFlag.Revision, + Revision: opts.templateSourceFlag.Revision, AllowOffline: opts.offlineFlag, } - log.Debug().Msgf("print git template: name=%s revision=%s offline=%v", name, opts.sourceFlag.Revision, opts.offlineFlag) + log.Debug().Msgf("print git template: name=%s revision=%s offline=%v", name, opts.templateSourceFlag.Revision, opts.offlineFlag) return printTemplate(NewGitValidator(sourceOpts, name), format) }