Skip to content

Commit

Permalink
Add getters to configure commands + Update README docs (#79)
Browse files Browse the repository at this point in the history
Add getters for zero-arg configure commands
Document config options in README
Show message for no base URL
Fixes + Version bump
  • Loading branch information
waseem-medhat authored Jan 28, 2025
1 parent 6a13d00 commit 950affe
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 9 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,57 @@ source ~/.zshrc
### 3. Login to the CLI

Run `bootdev login` to authenticate with your Boot.dev account. After authenticating, you're ready to go!

## Configuration

The Boot.dev CLI offers a couple of configuration options that are stored in a config file (default is `~/.bootdev.yaml`).

All commands have `-h`/`--help` flags if you want to see available options on the command line.

### Base URL for HTTP tests

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.

- To set the base URL run:

```bash
bootdev configure base_url <url>
```

*Make sure you include the protocol scheme (`http://`) in the URL.*

- To get the current base URL (the default is an empty string), run:

```bash
bootdev configure base_url
```

- To reset the base URL and revert to using the lessons' defaults, run:

```bash
bootdev configure base_url --reset
```

### CLI colors

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).

- To customize these colors, run:

```bash
bootdev configure colors --red <value> --green <value> --gray <value>
```

*You can use an [ANSI color code](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) or a hex string as the `<value>`.*

- To get the current colors, run:

```bash
bootdev configure colors
```

- To reset the colors to their default values, run:

```bash
bootdev configure colors --reset
```
27 changes: 19 additions & 8 deletions cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var defaultColors = map[string]string{
// the colors of the text output
var configureColorsCmd = &cobra.Command{
Use: "colors",
Short: "Change the CLI text colors",
Short: "Get or set the CLI text colors",
RunE: func(cmd *cobra.Command, args []string) error {
resetColors, err := cmd.Flags().GetBool("reset")
if err != nil {
Expand Down Expand Up @@ -57,21 +57,26 @@ var configureColorsCmd = &cobra.Command{
configColors[color] = configVal
}

showHelp := true
noFlags := true
for color, configVal := range configColors {
if configVal == "" {
continue
}

showHelp = false
noFlags = false
key := "color." + color
viper.Set(key, configVal)
style := lipgloss.NewStyle().Foreground(lipgloss.Color(configVal))
fmt.Println("set " + style.Render(key) + "!")
}

if showHelp {
return cmd.Help()
if noFlags {
for color := range configColors {
val := viper.GetString("color." + color)
style := lipgloss.NewStyle().Foreground(lipgloss.Color(val))
fmt.Printf(style.Render("%v: %v")+"\n", color, val)
}
return nil
}

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

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

if len(args) == 0 {
return cmd.Help()
baseURL := viper.GetString("override_base_url")
message := fmt.Sprintf("Base URL: %s", baseURL)
if baseURL == "" {
message = "No base URL set"
}
fmt.Println(message)
return nil
}

overrideBaseURL, err := url.Parse(args[0])
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.16.0
v1.16.1

0 comments on commit 950affe

Please sign in to comment.