github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/command/workspace_show.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package command
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  
    10  	"github.com/posener/complete"
    11  )
    12  
    13  type WorkspaceShowCommand struct {
    14  	Meta
    15  }
    16  
    17  func (c *WorkspaceShowCommand) Run(args []string) int {
    18  	args = c.Meta.process(args)
    19  	cmdFlags := c.Meta.extendedFlagSet("workspace show")
    20  	cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
    21  	if err := cmdFlags.Parse(args); err != nil {
    22  		c.Ui.Error(fmt.Sprintf("Error parsing command-line flags: %s\n", err.Error()))
    23  		return 1
    24  	}
    25  
    26  	workspace, err := c.Workspace()
    27  	if err != nil {
    28  		c.Ui.Error(fmt.Sprintf("Error selecting workspace: %s", err))
    29  		return 1
    30  	}
    31  	c.Ui.Output(workspace)
    32  
    33  	return 0
    34  }
    35  
    36  func (c *WorkspaceShowCommand) AutocompleteArgs() complete.Predictor {
    37  	return complete.PredictNothing
    38  }
    39  
    40  func (c *WorkspaceShowCommand) AutocompleteFlags() complete.Flags {
    41  	return nil
    42  }
    43  
    44  func (c *WorkspaceShowCommand) Help() string {
    45  	helpText := `
    46  Usage: terraform [global options] workspace show
    47  
    48    Show the name of the current workspace.
    49  `
    50  	return strings.TrimSpace(helpText)
    51  }
    52  
    53  func (c *WorkspaceShowCommand) Synopsis() string {
    54  	return "Show the name of the current workspace"
    55  }