Skip to content

Commit

Permalink
playground: make playground tag has higher priority than tiup
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar committed May 6, 2022
1 parent 378989e commit 5815fc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
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

0 comments on commit 5815fc6

Please sign in to comment.