generated from broadinstitute/golang-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
describe_command.go
75 lines (59 loc) · 1.76 KB
/
describe_command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package list
import (
"fmt"
"github.com/broadinstitute/thelma/internal/thelma/app"
"github.com/broadinstitute/thelma/internal/thelma/cli"
"github.com/broadinstitute/thelma/internal/thelma/cli/commands/bee/common/builders"
"github.com/broadinstitute/thelma/internal/thelma/cli/commands/bee/common/views"
"github.com/spf13/cobra"
)
const helpMessage = `Print detailed information about a BEE
Examples:
thelma bee describe -n <name>
`
type options struct {
name string
}
// flagNames the names of all this command's CLI flags are kept in a struct so they can be easily referenced in error messages
var flagNames = struct {
name string
}{
name: "name",
}
type describeCommand struct {
options options
}
func NewBeeDescribeCommand() cli.ThelmaCommand {
return &describeCommand{}
}
func (cmd *describeCommand) ConfigureCobra(cobraCommand *cobra.Command) {
cobraCommand.Use = "describe"
cobraCommand.Short = "Describe BEEs"
cobraCommand.Long = helpMessage
cobraCommand.Flags().StringVarP(&cmd.options.name, flagNames.name, "n", "NAME", "Required. Name of the BEE to describe")
}
func (cmd *describeCommand) PreRun(_ app.ThelmaApp, rc cli.RunContext) error {
// validate --name
if !rc.CobraCommand().Flags().Changed(flagNames.name) {
return fmt.Errorf("no environment name specified; --%s is required", flagNames.name)
}
return nil
}
func (cmd *describeCommand) Run(app app.ThelmaApp, rc cli.RunContext) error {
// only show dynamic environments
bees, err := builders.NewBees(app)
if err != nil {
return err
}
bee, err := bees.GetBee(cmd.options.name)
if err != nil {
return err
}
view := views.DescribeBeeEnv(bee)
rc.SetOutput(view)
return nil
}
func (cmd *describeCommand) PostRun(_ app.ThelmaApp, _ cli.RunContext) error {
// nothing to do here
return nil
}