github.com/opentofu/opentofu@v1.7.1/internal/command/workspace_show.go (about)

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