Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
6c29207
Initial scaffold
ammario Feb 25, 2023
12dcc45
Add Duration
ammario Feb 25, 2023
d1e2e15
Begin converting AccessURL
ammario Feb 25, 2023
8db4626
fixup! Begin converting AccessURL
ammario Feb 25, 2023
dc81f47
Start migrating Server
ammario Feb 25, 2023
d511001
Convert a couple more fields
ammario Feb 26, 2023
8cc406e
replace DeploymentConfig[T] with bigcli.[T]
ammario Feb 26, 2023
18b2552
Remove .Value calls
ammario Feb 26, 2023
bad7aca
Finish destroying newConfig
ammario Feb 26, 2023
f075ad5
delete deployment/
ammario Feb 26, 2023
69600d7
rewrite server.go
ammario Feb 26, 2023
63159a6
ugh
ammario Feb 26, 2023
03b08fa
Server boots
ammario Feb 26, 2023
e0d6c1e
Move critical options code into `codersdk`
ammario Feb 26, 2023
5bebd0f
DefaultCacheDir
ammario Feb 26, 2023
2c7b39d
Merge remote-tracking branch 'origin/main' into bigcli
ammario Feb 26, 2023
05b3a10
Fix config dir bug
ammario Feb 26, 2023
dcbd0d8
update golden --help
ammario Feb 26, 2023
fc06f64
Support NoOptDefValue
ammario Feb 26, 2023
d31fa37
Don't hide pflag.FlagSet
ammario Feb 26, 2023
0d7d557
Help template scaffold
ammario Feb 26, 2023
f3d45d3
Show env in help output
ammario Feb 26, 2023
d322114
Merge remote-tracking branch 'origin/main' into bigcli
ammario Feb 26, 2023
8f9d44b
Write more descriptions
ammario Feb 26, 2023
acac92d
Organize telemetry
ammario Feb 26, 2023
1c8359b
Finish grouping up flags
ammario Feb 26, 2023
8d0020f
Render subcommands
ammario Feb 26, 2023
882a80f
Convert Groups to first class bigcli feature
ammario Feb 26, 2023
ae858b4
deepMapNode?
ammario Feb 26, 2023
b34d481
Add YAML tags everywhere.......
ammario Feb 26, 2023
e0e113b
Minor changes
ammario Feb 26, 2023
02c8f6c
Group Enterprise flags
ammario Feb 26, 2023
000466f
Massive refactor to improve help formatting
ammario Feb 27, 2023
c6133f2
Improve help formatting again
ammario Feb 27, 2023
ab21e8f
Send group descriptions to YAML
ammario Feb 27, 2023
b816b1a
Fix YAML tests
ammario Feb 27, 2023
559b046
make gen
ammario Feb 27, 2023
3b24149
Pass linter
ammario Feb 27, 2023
e422c1d
Fix slim bugs
ammario Feb 27, 2023
ea6c3b7
Start frontend... about to go to sleep 🥱
ammario Feb 27, 2023
d4aa8d3
Merge remote-tracking branch 'origin/main' into bigcli
ammario Feb 27, 2023
58b6324
Fix remaining go compilation errors
ammario Feb 27, 2023
cae2eab
Do some type generation
ammario Feb 27, 2023
d4bd380
Fix most broken frontend code...
ammario Feb 27, 2023
8a493ef
Add envparse library
ammario Feb 27, 2023
84b59be
Add legacy git auth env support
ammario Feb 27, 2023
ac3507f
Fix Git Provider rendering in frontend
ammario Feb 27, 2023
95db142
Remove unused lint rules
ammario Feb 27, 2023
790f45a
Update golden files
ammario Feb 27, 2023
360b600
Fix all stories
ammario Feb 28, 2023
2344013
Fix server tests
ammario Feb 28, 2023
394fbfa
Merge remote-tracking branch 'origin/main' into bigcli
ammario Feb 28, 2023
ac909b5
Disable clidocsgen.. for now
ammario Feb 28, 2023
8a2637d
Server tests pass?
ammario Feb 28, 2023
3ed919e
Start figuring out CLI array bug
ammario Feb 28, 2023
d397839
bigcli: fix slice parsing
ammario Feb 28, 2023
957500b
fix remaining calls to deprecated "experimental"
ammario Feb 28, 2023
0890005
Fix more tests
ammario Feb 28, 2023
622df7f
make gen
ammario Feb 28, 2023
362618e
Fix another server test bug
ammario Feb 28, 2023
2fa8b78
Fix logger!
ammario Feb 28, 2023
28e4b07
fix access url test
ammario Feb 28, 2023
410ad26
make gen
ammario Feb 28, 2023
5c3f648
fix frontend!
ammario Feb 28, 2023
f29889f
Merge remote-tracking branch 'origin/main' into bigcli
ammario Feb 28, 2023
6ced9cf
Debug log gitAuthConfigs
ammario Feb 28, 2023
d9d1592
No more implicit options
ammario Mar 1, 2023
74c6da2
Re-enable cli docs gen
ammario Mar 1, 2023
9e53c96
De-pointer DeploymentValues
ammario Mar 1, 2023
06f82b5
Decompose DeploymentConfig
ammario Mar 1, 2023
2f5a522
Some comments
ammario Mar 1, 2023
53e92fc
Move envparse into bigcli
ammario Mar 6, 2023
e9e2908
Minor changes
ammario Mar 6, 2023
c3a11fd
Add context to clitest.Start
ammario Mar 6, 2023
a090cd4
Remove dead function
ammario Mar 6, 2023
d9a8da6
Merge remote-tracking branch 'origin/main' into bigcli
ammario Mar 6, 2023
e53367a
Fix FE
ammario Mar 6, 2023
6252316
make lint passes
ammario Mar 6, 2023
bf1a099
Pass highlyConfigurable
ammario Mar 6, 2023
274d5c5
Context bug
ammario Mar 6, 2023
a213d25
Rename to clibase
ammario Mar 6, 2023
2938980
fix slim build
ammario Mar 6, 2023
140438e
Merge remote-tracking branch 'origin/main' into bigcli
ammario Mar 7, 2023
46936f5
Fix merge issues
ammario Mar 7, 2023
06277c4
Set max token lifetime correctly
ammario Mar 7, 2023
fc8e6ca
Command -> Cmd
ammario Mar 7, 2023
2a74445
Typo
ammario Mar 7, 2023
3cfb4bf
Show disabled badge in zero option table
ammario Mar 7, 2023
4d8bc75
Merge remote-tracking branch 'origin/main' into bigcli
ammario Mar 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Massive refactor to improve help formatting
  • Loading branch information
ammario committed Feb 27, 2023
commit 000466f57c93212394c575421d8706b5a00b0c0f
74 changes: 74 additions & 0 deletions cli/bigcli/bigcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,77 @@
// cobra/viper. It's also a candidate to be broken out into its own open-source
// library, so we avoid deep coupling with Coder concepts.
package bigcli

import (
"strings"

"golang.org/x/exp/maps"
)

// Group describes a hierarchy of groups that an option or command belongs to.
type Group struct {
Parent *Group
Name string
Children []Group
Description string
}

func (g *Group) AddChild(child Group) {
child.Parent = g
g.Children = append(g.Children, child)
}

// Ancestry returns the group and all of its parents, in order.
func (g *Group) Ancestry() []Group {
groups := []Group{*g}
for p := g.Parent; p != nil; p = p.Parent {
// Prepend to the slice so that the order is correct.
groups = append([]Group{*p}, groups...)
}
return groups
}

func (g *Group) FullName() string {
var names []string
for _, g := range g.Ancestry() {
names = append(names, g.Name)
}
return strings.Join(names, " / ")
}

// Annotations is an arbitrary key-mapping used to extend the Option and Command types.
// Its methods won't panic if the map is nil.
type Annotations map[string]string

// Mark sets a value on the attonations map, creating one
// if it doesn't exist. Mark does not mutate the original and
// returns a copy. It is suitable for chaining.
func (a Annotations) Mark(key string, value string) Annotations {
var aa Annotations
if a != nil {
aa = maps.Clone(a)
} else {
aa = make(Annotations)
}
aa[key] = value
return aa
}

// IsSet returns true if the key is set in the annotations map.
func (a Annotations) IsSet(key string) bool {
if a == nil {
return false
}
_, ok := a[key]
return ok
}

// Get retrieves a key from the map, returning false if the key is not found
// or the map is nil.
func (a Annotations) Get(key string) (string, bool) {
if a == nil {
return "", false
}
v, ok := a[key]
return v, ok
}
28 changes: 10 additions & 18 deletions cli/bigcli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import "strings"

// Command describes an executable command.
type Command struct {
// Parents is a list of parent commands, with
// the root command at index 0.
Parents []*Command
// Parent is the direct parent of the command.
Parent *Command
// Children is a list of direct descendants.
Children []*Command
// Use is provided in form "command [flags] [args...]".
Expand All @@ -15,8 +14,9 @@ type Command struct {
Short string
// Long is a detailed description of the command,
// presented on its help page. It may contain examples.
Long string
Options OptionSet
Long string
Options OptionSet
Annotations Annotations
}

// Name returns the first word in the Use string.
Expand All @@ -28,8 +28,9 @@ func (c *Command) Name() string {
// as seen on the command line.
func (c *Command) FullName() string {
var names []string
for _, p := range c.Parents {
names = append(names, p.Name())

if c.Parent != nil {
names = append(names, c.Parent.FullName())
}
names = append(names, c.Name())
return strings.Join(names, " ")
Expand All @@ -39,18 +40,9 @@ func (c *Command) FullName() string {
// by the usage of its parents.
func (c *Command) FullUsage() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we need to show parent command usage in addition to current command usage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do so in the help template, perhaps not validly.

var uses []string
for _, p := range c.Parents {
uses = append(uses, p.Use)
if c.Parent != nil {
uses = append(uses, c.Parent.FullUsage())
}
uses = append(uses, c.Use)
return strings.Join(uses, " ")
}

// Parent returns the direct parent of the command,
// or nil if there are no parents.
func (c *Command) Parent() *Command {
if len(c.Parents) == 0 {
return nil
}
return c.Parents[len(c.Parents)-1]
}
40 changes: 1 addition & 39 deletions cli/bigcli/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,13 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/iancoleman/strcase"
"github.com/spf13/pflag"
"golang.org/x/exp/maps"
"golang.org/x/xerrors"
)

// Disable is a sentinel value for Option.Flag, Option.Env, and Option.YAML to disable
// features.
const Disable = "-"

// Annotations is an arbitrary key-mapping used to extend the Option type.
// Its methods won't panic if the map is nil.
type Annotations map[string]string

// Mark sets a value on the attonations map, creating one
// if it doesn't exist. Mark does not mutate the original and
// returns a copy. It is suitable for chaining.
func (a Annotations) Mark(key string, value string) Annotations {
var aa Annotations
if a != nil {
aa = maps.Clone(a)
} else {
aa = make(Annotations)
}
aa[key] = value
return aa
}

// IsSet returns true if the key is set in the annotations map.
func (a Annotations) IsSet(key string) bool {
if a == nil {
return false
}
_, ok := a[key]
return ok
}

// Get retrieves a key from the map, returning false if the key is not found
// or the map is nil.
func (a Annotations) Get(key string) (string, bool) {
if a == nil {
return "", false
}
v, ok := a[key]
return v, ok
}

// Option is a configuration option for a CLI application.
type Option struct {
Name string
Expand Down Expand Up @@ -81,7 +43,7 @@ type Option struct {

// Group is a group hierarchy that helps organize this option in help, configs
// and other documentation.
Group []string
Group Group

// UseInstead is a list of options that should be used instead of this one.
// The field is used to generate a deprecation warning.
Expand Down
7 changes: 4 additions & 3 deletions cli/bigcli/yaml.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package bigcli

import (
"github.com/iancoleman/strcase"
"strings"

"github.com/mitchellh/go-wordwrap"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -58,8 +59,8 @@ func (s OptionSet) ToYAML() (*yaml.Node, error) {
Value: opt.Value.String(),
}
var group []string
for _, g := range opt.Group {
group = append(group, strcase.ToSnake(g))
for _, g := range opt.Group.Ancestry() {
group = append(group, strings.ToLower(g.Name))
}
parent := deepMapNode(&root, group)
parent.Content = append(
Expand Down
2 changes: 1 addition & 1 deletion cli/bigcli/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestOption_ToYAML(t *testing.T) {
Value: &workspaceName,
Default: "billie",
Description: "The workspace's name",
Group: []string{"Names"},
Group: bigcli.Group{Name: "Names"},
},
}

Expand Down
6 changes: 2 additions & 4 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Close
// These parents and children will be moved once we convert the
// rest of the `cli` package to bigcli.
flagSet.Usage = usageFn(cmd.ErrOrStderr(), &bigcli.Command{
Parents: []*bigcli.Command{
{
Use: "coder",
},
Parent: &bigcli.Command{
Use: "coder",
},
Children: []*bigcli.Command{
{
Expand Down
53 changes: 7 additions & 46 deletions cli/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,6 @@ type optionGroup struct {
Options bigcli.OptionSet
}

var optionGroupDescriptions = map[string]string{
"Networking": `
Configure TLS, the wildcard access URL, bind addresses, access URLs, etc.
`,
"Networking / DERP": `
Most Coder deployments never have to think about DERP because all connections
between workspaces and users are peer-to-peer. However, when Coder cannot establish
a peer to peer connection, Coder uses a distributed relay network backed by
Tailscale and WireGuard.
`,
"Networking / TLS": `
Configure TLS / HTTPS for your Coder deployment. If you're running
Coder behind a TLS-terminating reverse proxy or are accessing Coder over a
secure link, you can safely ignore these settings.
`,
`Introspection`: `
Configure logging, tracing, and metrics exporting.
`,
`oAuth2`: `
Configure login and user-provisioning with GitHub via oAuth2.
`,
`OIDC`: `
Configure login and user-provisioning with OIDC.
`,
`Telemetry`: `
Telemetry is critical to our ability to improve Coder. We strip all personal
information before sending data to our servers. Please only disable telemetry
when required by your organization's security policy.
`,
`Provisioning`: `
Tune the behavior of the provisioner, which is responsible for creating,
updating, and deleting workspace resources.
`,
`Config`: `
Use a YAML configuration file when your server launch become unwieldy.
`,
}

const envPrefix = "CODER_"

var usageTemplate = template.Must(
Expand Down Expand Up @@ -102,7 +64,8 @@ var usageTemplate = template.Must(
"isDeprecated": func(opt bigcli.Option) bool {
return len(opt.UseInstead) > 0
},
"formatDescription": func(s string) string {
"formatGroupDescription": func(s string) string {
s = strings.ReplaceAll(s, "\n", "")
s = "\n" + s + "\n"
s = wordwrap.WrapString(s, 60)
return s
Expand All @@ -115,10 +78,8 @@ var usageTemplate = template.Must(
}}

enterpriseGroup := optionGroup{
Name: "Enterprise",
Description: `
These options are only available in the Enterprise Edition.
`,
Name: "Enterprise",
Description: `These options are only available in the Enterprise Edition.`,
}

// Sort options lexicographically.
Expand All @@ -136,13 +97,13 @@ These options are only available in the Enterprise Edition.
enterpriseGroup.Options = append(enterpriseGroup.Options, opt)
continue
}
if len(opt.Group) == 0 {
if len(opt.Group.Ancestry()) == 0 {
// Just add option to default group.
groups[0].Options = append(groups[0].Options, opt)
continue
}

groupName := strings.Join(opt.Group, " / ")
groupName := opt.Group.FullName()

for i, foundGroup := range groups {
if foundGroup.Name != groupName {
Expand All @@ -154,7 +115,7 @@ These options are only available in the Enterprise Edition.

groups = append(groups, optionGroup{
Name: groupName,
Description: optionGroupDescriptions[groupName],
Description: opt.Group.Description,
Options: bigcli.OptionSet{opt},
})
}
Expand Down
9 changes: 4 additions & 5 deletions cli/usage.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ usage: {{.FullUsage}}

{{- range $index, $group := optionGroups . }}
{{ with $group.Name }} {{- print $group.Name " Options" | prettyHeader }} {{ else -}} {{ prettyHeader "Options"}}{{- end -}}
{{- with $group.Description }}
{{ " " }}
{{- . -}}
{{- with $group.Description }}
{{ formatGroupDescription . -}}
{{ end }}
{{- range $index, $option := $group.Options }}
{{- with flagName $option }}
--{{- . -}} {{ end }} {{- with $option.FlagShorthand }}, -{{- . -}} {{ end }}
{{- with envName $option }}, ${{ . }} {{ end }}
{{- with $option.Default }} (default: {{.}}) {{ end }}
{{- with $option.Description }}
{{- "" }}
{{- $desc := formatDescription $option.Description }}
{{- indent $desc 2}}
{{- $desc := wordWrap $option.Description 60 }}
{{ indent $desc 2}}
{{- if isDeprecated $option }} DEPRECATED {{ end }}
{{- end -}}
{{- end }}
Expand Down
Loading