Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playground: make playground tag has higher priority than tiup #1869

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,25 @@ the latest stable version will be downloaded from the repository.`,
return nil
case "--binpath":
if len(args) < 2 {
return fmt.Errorf("flag needs an argument: %s", args[0])
return fmt.Errorf("flag %s needs an argument", args[0])
}
binPath = args[1]
args = args[2:]
case "--tag", "-T":
if len(args) < 2 {
return fmt.Errorf("flag needs an argument: %s", args[0])
return fmt.Errorf("flag %s needs an argument", args[0])
}
tag = args[1]
args = args[2:]
}

// component may use tag from environment variable. as workaround, make tiup set the same tag
for i := 0; i < len(args)-1; i++ {
if args[i] == "--tag" || args[i] == "-T" {
tag = args[i+1]
}
}

if len(args) < 1 {
return cmd.Help()
}
Expand Down
21 changes: 9 additions & 12 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,21 @@ Examples:
if tiupHome == "" {
tiupHome, _ = getAbsolutePath(filepath.Join("~", localdata.ProfileDirName))
}
if tiupDataDir == "" {
if tag == "" {
dataDir = filepath.Join(tiupHome, localdata.DataParentDir, utils.Base62Tag())
} else {
dataDir = filepath.Join(tiupHome, localdata.DataParentDir, tag)
}
if dataDir == "" {
return errors.Errorf("cannot read environment variable %s nor %s", localdata.EnvNameInstanceDataDir, localdata.EnvNameHome)
}
switch {
case tag != "":
dataDir = filepath.Join(tiupHome, localdata.DataParentDir, tag)
err := os.MkdirAll(dataDir, os.ModePerm)
if err != nil {
return err
}
} else {
case tiupDataDir != "":
dataDir = tiupDataDir
tag = dataDir[strings.LastIndex(dataDir, "/")+1:]
default:
tag = utils.Base62Tag()
dataDir = filepath.Join(tiupHome, localdata.DataParentDir, tag)
}
instanceName := dataDir[strings.LastIndex(dataDir, "/")+1:]
fmt.Printf("\033]0;TiUP Playground: %s\a", instanceName)
fmt.Printf("\033]0;TiUP Playground: %s\a", tag)
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down