Skip to content

Commit 950affe

Browse files
Add getters to configure commands + Update README docs (#79)
Add getters for zero-arg configure commands Document config options in README Show message for no base URL Fixes + Version bump
1 parent 6a13d00 commit 950affe

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

Diff for: README.md

+54
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,57 @@ source ~/.zshrc
8383
### 3. Login to the CLI
8484

8585
Run `bootdev login` to authenticate with your Boot.dev account. After authenticating, you're ready to go!
86+
87+
## Configuration
88+
89+
The Boot.dev CLI offers a couple of configuration options that are stored in a config file (default is `~/.bootdev.yaml`).
90+
91+
All commands have `-h`/`--help` flags if you want to see available options on the command line.
92+
93+
### Base URL for HTTP tests
94+
95+
For lessons with HTTP tests, you can configure the CLI with a base URL that overrides any lesson's default. A common use case for that is when you want to run your server on a port other than the one specified in the lesson.
96+
97+
- To set the base URL run:
98+
99+
```bash
100+
bootdev configure base_url <url>
101+
```
102+
103+
*Make sure you include the protocol scheme (`http://`) in the URL.*
104+
105+
- To get the current base URL (the default is an empty string), run:
106+
107+
```bash
108+
bootdev configure base_url
109+
```
110+
111+
- To reset the base URL and revert to using the lessons' defaults, run:
112+
113+
```bash
114+
bootdev configure base_url --reset
115+
```
116+
117+
### CLI colors
118+
119+
The CLI text output is rendered with extra colors: green (e.g., success messages), red (e.g., error messages), and gray (e.g., secondary text).
120+
121+
- To customize these colors, run:
122+
123+
```bash
124+
bootdev configure colors --red <value> --green <value> --gray <value>
125+
```
126+
127+
*You can use an [ANSI color code](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) or a hex string as the `<value>`.*
128+
129+
- To get the current colors, run:
130+
131+
```bash
132+
bootdev configure colors
133+
```
134+
135+
- To reset the colors to their default values, run:
136+
137+
```bash
138+
bootdev configure colors --reset
139+
```

Diff for: cmd/configure.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var defaultColors = map[string]string{
2626
// the colors of the text output
2727
var configureColorsCmd = &cobra.Command{
2828
Use: "colors",
29-
Short: "Change the CLI text colors",
29+
Short: "Get or set the CLI text colors",
3030
RunE: func(cmd *cobra.Command, args []string) error {
3131
resetColors, err := cmd.Flags().GetBool("reset")
3232
if err != nil {
@@ -57,21 +57,26 @@ var configureColorsCmd = &cobra.Command{
5757
configColors[color] = configVal
5858
}
5959

60-
showHelp := true
60+
noFlags := true
6161
for color, configVal := range configColors {
6262
if configVal == "" {
6363
continue
6464
}
6565

66-
showHelp = false
66+
noFlags = false
6767
key := "color." + color
6868
viper.Set(key, configVal)
6969
style := lipgloss.NewStyle().Foreground(lipgloss.Color(configVal))
7070
fmt.Println("set " + style.Render(key) + "!")
7171
}
7272

73-
if showHelp {
74-
return cmd.Help()
73+
if noFlags {
74+
for color := range configColors {
75+
val := viper.GetString("color." + color)
76+
style := lipgloss.NewStyle().Foreground(lipgloss.Color(val))
77+
fmt.Printf(style.Render("%v: %v")+"\n", color, val)
78+
}
79+
return nil
7580
}
7681

7782
err = viper.WriteConfig()
@@ -84,8 +89,8 @@ var configureColorsCmd = &cobra.Command{
8489

8590
// configureBaseURLCmd represents the `configure base_url` command
8691
var configureBaseURLCmd = &cobra.Command{
87-
Use: "base_url",
88-
Short: "Set the base URL for HTTP tests, overriding lesson defaults",
92+
Use: "base_url [url]",
93+
Short: "Get or set the base URL for HTTP tests, overriding lesson defaults",
8994
Args: cobra.RangeArgs(0, 1),
9095
RunE: func(cmd *cobra.Command, args []string) error {
9196
resetOverrideBaseURL, err := cmd.Flags().GetBool("reset")
@@ -104,7 +109,13 @@ var configureBaseURLCmd = &cobra.Command{
104109
}
105110

106111
if len(args) == 0 {
107-
return cmd.Help()
112+
baseURL := viper.GetString("override_base_url")
113+
message := fmt.Sprintf("Base URL: %s", baseURL)
114+
if baseURL == "" {
115+
message = "No base URL set"
116+
}
117+
fmt.Println(message)
118+
return nil
108119
}
109120

110121
overrideBaseURL, err := url.Parse(args[0])

Diff for: version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.16.0
1+
v1.16.1

0 commit comments

Comments
 (0)