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

Put os.Stdin size to NewReaderSize instead NewReader #441

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 19 additions & 13 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func newContextCommand(config *settings.Config) *cobra.Command {
}

listCommand := &cobra.Command{
Short: "List all contexts",
Use: "list <vcs-type> <org-name>",
Short: "List all contexts",
Use: "list <vcs-type> <org-name>",
PreRunE: initClient,
RunE: func(cmd *cobra.Command, args []string) error {
return listContexts(cl, args[0], args[1])
Expand All @@ -41,8 +41,8 @@ func newContextCommand(config *settings.Config) *cobra.Command {
}

showContextCommand := &cobra.Command{
Short: "Show a context",
Use: "show <vcs-type> <org-name> <context-name>",
Short: "Show a context",
Use: "show <vcs-type> <org-name> <context-name>",
PreRunE: initClient,
RunE: func(cmd *cobra.Command, args []string) error {
return showContext(cl, args[0], args[1], args[2])
Expand All @@ -51,8 +51,8 @@ func newContextCommand(config *settings.Config) *cobra.Command {
}

storeCommand := &cobra.Command{
Short: "Store a new environment variable in the named context. The value is read from stdin.",
Use: "store-secret <vcs-type> <org-name> <context-name> <secret name>",
Short: "Store a new environment variable in the named context. The value is read from stdin.",
Use: "store-secret <vcs-type> <org-name> <context-name> <secret name>",
PreRunE: initClient,
RunE: func(cmd *cobra.Command, args []string) error {
return storeEnvVar(cl, args[0], args[1], args[2], args[3])
Expand All @@ -61,8 +61,8 @@ func newContextCommand(config *settings.Config) *cobra.Command {
}

removeCommand := &cobra.Command{
Short: "Remove an environment variable from the named context",
Use: "remove-secret <vcs-type> <org-name> <context-name> <secret name>",
Short: "Remove an environment variable from the named context",
Use: "remove-secret <vcs-type> <org-name> <context-name> <secret name>",
PreRunE: initClient,
RunE: func(cmd *cobra.Command, args []string) error {
return removeEnvVar(cl, args[0], args[1], args[2], args[3])
Expand All @@ -71,8 +71,8 @@ func newContextCommand(config *settings.Config) *cobra.Command {
}

createContextCommand := &cobra.Command{
Short: "Create a new context",
Use: "create <vcs-type> <org-name> <context-name>",
Short: "Create a new context",
Use: "create <vcs-type> <org-name> <context-name>",
PreRunE: initClient,
RunE: func(cmd *cobra.Command, args []string) error {
return createContext(cl, args[0], args[1], args[2])
Expand All @@ -82,8 +82,8 @@ func newContextCommand(config *settings.Config) *cobra.Command {

force := false
deleteContextCommand := &cobra.Command{
Short: "Delete the named context",
Use: "delete <vcs-type> <org-name> <context-name>",
Short: "Delete the named context",
Use: "delete <vcs-type> <org-name> <context-name>",
PreRunE: initClient,
RunE: func(cmd *cobra.Command, args []string) error {
return deleteContext(cl, force, args[0], args[1], args[2])
Expand Down Expand Up @@ -176,7 +176,13 @@ func readSecretValue() (string, error) {
return string(bytes), err
} else {
fmt.Print("Enter secret value and press enter: ")
reader := bufio.NewReader(os.Stdin)

buffSize, err := os.Stdin.Stat()
if err != nil {
return "", err
}

reader := bufio.NewReaderSize(os.Stdin, int(buffSize.Size()))
str, err := reader.ReadString('\n')
return strings.TrimRight(str, "\n"), err
}
Expand Down