Skip to content

Commit

Permalink
Merge branch 'master' into add_privilege_escalation_methods_to_envinit
Browse files Browse the repository at this point in the history
  • Loading branch information
darkelf21cn authored Sep 21, 2020
2 parents 2c6aeac + 65fdf56 commit 2b53da1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
58 changes: 58 additions & 0 deletions cmd/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
"os"

"github.com/pingcap/tiup/pkg/localdata"
"github.com/spf13/cobra"
)

var envList = []string{
localdata.EnvNameHome,
localdata.EnvNameTelemetryStatus,
localdata.EnvNameTelemetryUUID,
localdata.EnvNameSSHPassPrompt,
localdata.EnvNameSSHPath,
localdata.EnvNameSCPPath,
}

func newEnvCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "env [name1...N]",
Short: "Show the list of system environment variable that related to TiUP",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
showEnvList(true, envList...)
return nil
}
showEnvList(false, args...)
return nil
},
}

return cmd
}

func showEnvList(withKey bool, names ...string) {
for _, name := range names {
if withKey {
fmt.Printf("%s=\"%s\"\n", name, os.Getenv(name))
} else {
fmt.Printf("%s\n", os.Getenv(name))
}
}
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ the latest stable version will be downloaded from the repository.`,
newMirrorCmd(),
newTelemetryCmd(),
newCompletionCmd(),
newEnvCmd(),
)

originHelpFunc := rootCmd.HelpFunc()
Expand Down
2 changes: 2 additions & 0 deletions pkg/localdata/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var DefaultTiupHome string
// ProfileDirName is the name of the profile directory to be used
var ProfileDirName = ".tiup"

// Notice: if you try to add a new env name which is notable by the user, shou should
// add it to cmd/env.go:envList so that the command `tiup env` will show that env.
const (
// ComponentParentDir represent the parent directory of all downloaded components
ComponentParentDir = "components"
Expand Down
2 changes: 2 additions & 0 deletions tests/tiup/test_tiup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ tiup update tidb
tiup status
tiup clean --all
tiup help tidb
tiup env
TIUP_SSHPASS_PROMPT="password" tiup env TIUP_SSHPASS_PROMPT | grep password
tiup uninstall
tiup uninstall tidb:v3.0.13
tiup uninstall tidb --all
Expand Down

0 comments on commit 2b53da1

Please sign in to comment.