Skip to content

Commit

Permalink
fix: add workdir to meta flag of kusion cli (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-hm19 authored Apr 26, 2024
1 parent b999f67 commit 13fb753
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/cmd/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type MetaFlags struct {
Workspace *string

Backend *string

WorkDir *string
}

// MetaOptions are the meta-options that are available on all or most commands.
Expand All @@ -52,10 +54,12 @@ type MetaOptions struct {
func NewMetaFlags() *MetaFlags {
workspace := ""
backendType := ""
workDir := ""

return &MetaFlags{
Workspace: &workspace,
Backend: &backendType,
WorkDir: &workDir,
}
}

Expand All @@ -67,14 +71,25 @@ func (f *MetaFlags) AddFlags(cmd *cobra.Command) {
if f.Backend != nil {
cmd.Flags().StringVarP(f.Backend, "backend", "", *f.Backend, i18n.T("The backend to use, supports 'local', 'oss' and 's3'."))
}
if f.WorkDir != nil {
cmd.Flags().StringVarP(f.WorkDir, "workdir", "", *f.WorkDir, i18n.T("The work directory to run Kusion CLI."))
}
}

// ToOptions converts MetaFlags to MetaOptions.
func (f *MetaFlags) ToOptions() (*MetaOptions, error) {
opts := &MetaOptions{}

// Parse project and currentStack of work directory
refProject, refStack, err := project.DetectProjectAndStacks()
var refProject *v1.Project
var refStack *v1.Stack
var err error
if f.WorkDir != nil && *f.WorkDir != "" {
refProject, refStack, err = project.DetectProjectAndStackFrom(*f.WorkDir)
} else {
refProject, refStack, err = project.DetectProjectAndStacks()
}

if err != nil {
return nil, err
}
Expand Down

0 comments on commit 13fb753

Please sign in to comment.