mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-02 19:47:54 +00:00 
			
		
		
		
	@mitchellh suggested we fork `cli` and switch to that. Since we primarily use the interfaces in `cli`, and the new fork has not changed those, this is (mostly) a drop-in replacement. A small fix will be necessary for Vault Enterprise, I believe.
		
			
				
	
	
		
			57 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright (c) HashiCorp, Inc.
 | 
						|
// SPDX-License-Identifier: BUSL-1.1
 | 
						|
 | 
						|
package command
 | 
						|
 | 
						|
import (
 | 
						|
	"strings"
 | 
						|
 | 
						|
	"github.com/hashicorp/cli"
 | 
						|
	"github.com/posener/complete"
 | 
						|
)
 | 
						|
 | 
						|
var (
 | 
						|
	_ cli.Command             = (*PrintTokenCommand)(nil)
 | 
						|
	_ cli.CommandAutocomplete = (*PrintTokenCommand)(nil)
 | 
						|
)
 | 
						|
 | 
						|
type PrintTokenCommand struct {
 | 
						|
	*BaseCommand
 | 
						|
}
 | 
						|
 | 
						|
func (c *PrintTokenCommand) Synopsis() string {
 | 
						|
	return "Prints the vault token currently in use"
 | 
						|
}
 | 
						|
 | 
						|
func (c *PrintTokenCommand) Help() string {
 | 
						|
	helpText := `
 | 
						|
Usage: vault print token
 | 
						|
 | 
						|
  Prints the value of the Vault token that will be used for commands, after
 | 
						|
  taking into account the configured token-helper and the environment.
 | 
						|
 | 
						|
      $ vault print token
 | 
						|
 | 
						|
`
 | 
						|
	return strings.TrimSpace(helpText)
 | 
						|
}
 | 
						|
 | 
						|
func (c *PrintTokenCommand) AutocompleteArgs() complete.Predictor {
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func (c *PrintTokenCommand) AutocompleteFlags() complete.Flags {
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func (c *PrintTokenCommand) Run(args []string) int {
 | 
						|
	client, err := c.Client()
 | 
						|
	if err != nil {
 | 
						|
		c.UI.Error(err.Error())
 | 
						|
		return 2
 | 
						|
	}
 | 
						|
 | 
						|
	c.UI.Output(client.Token())
 | 
						|
	return 0
 | 
						|
}
 |