Skip to content

Commit

Permalink
Fix token creation command
Browse files Browse the repository at this point in the history
  • Loading branch information
royroyee committed Feb 16, 2024
1 parent 06450d0 commit 55006d8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/token/token_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ var tokenCreateCmd = &cobra.Command{
var tokenRequest auth.APITokenRequest
var err error

if name == "" || (limit == false && expiresAt == 0) {
if name == "" || (limit == true && expiresAt == 0) {
tokenRequest, err = promptForToken()
if err != nil {
utils.CliError("Error during token prompt: %v", err)
}
} else {
tokenRequest = auth.APITokenRequest{Name: name}

if !limit {
if limit && expiresAt > 0 {
tokenRequest.ExpiresAt = utils.TimeFormat(expiresAt)
}
}
Expand All @@ -57,14 +57,14 @@ func init() {
var expiresAt int

tokenCreateCmd.Flags().StringVarP(&name, "name", "n", "", "A name to remember the token easily.")
tokenCreateCmd.Flags().BoolVarP(&limit, "limit", "l", false, "Set to true to apply usage limits.")
tokenCreateCmd.Flags().BoolVarP(&limit, "limit", "l", true, "Set to true to apply usage limits.")
tokenCreateCmd.Flags().IntVar(&expiresAt, "expiration-in-days", 0, "This token can be used by the specified time. (in days)")
}

func promptForToken() (auth.APITokenRequest, error) {
var tokenRequest auth.APITokenRequest
tokenRequest.Name = utils.PromptForRequiredInput("Token name:")
if !utils.PromptForBool("limit: ") {
if utils.PromptForBool("Limit: ") {
tokenRequest.ExpiresAt = utils.TimeFormat(utils.PromptForIntInput("Valid through (in days): "))
} else {
tokenRequest.ExpiresAt = nil
Expand Down

0 comments on commit 55006d8

Please sign in to comment.