Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ func InitConfig(ctx context.Context, clients *shared.ClientFactory, rootCmd *cob
clients.Config.SystemConfig.SetCustomConfigDirPath(clients.Config.ConfigDirFlag)
}

// Accessible mode implies no-color
if clients.Config.Accessible {
clients.Config.NoColor = true
}

// Init color and formatting
style.ToggleStyles(clients.IO.IsTTY() && !clients.Config.NoColor)
style.ToggleSpinner(clients.IO.IsTTY() && !clients.Config.NoColor && !clients.Config.DebugEnabled)
Expand Down
10 changes: 10 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"
"testing"

"github.com/slackapi/slack-cli/internal/config"
"github.com/slackapi/slack-cli/internal/iostreams"
"github.com/slackapi/slack-cli/internal/shared"
"github.com/slackapi/slack-cli/internal/slackcontext"
Expand Down Expand Up @@ -194,6 +195,15 @@ func TestVersionFlags(t *testing.T) {
assert.True(t, testutil.ContainsSemVer(output), `-v should output the version number but yielded "%s"`, output)
}

func Test_AccessibleImpliesNoColor(t *testing.T) {
cfg := &config.Config{Accessible: true}
// Simulate the logic from PersistentPreRunE
if cfg.Accessible {
cfg.NoColor = true
}
assert.True(t, cfg.NoColor, "--accessible should imply --no-color")
}

Comment on lines +198 to +206
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
func Test_AccessibleImpliesNoColor(t *testing.T) {
cfg := &config.Config{Accessible: true}
// Simulate the logic from PersistentPreRunE
if cfg.Accessible {
cfg.NoColor = true
}
assert.True(t, cfg.NoColor, "--accessible should imply --no-color")
}

🪓 note: I'm not sure this test is so useful against regressions here?

func Test_NewSuggestion(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())

Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Config struct {
SlackTestTraceFlag bool
TeamFlag string
TokenFlag string
Accessible bool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🌲 thought: As we're introducing this, should we include the environment variable similar?

ACCESSIBLE

We recommend setting this through an environment variable or configuration option to allow the user to control accessibility.

🔗 https://github.com/charmbracelet/huh?tab=readme-ov-file#accessibility

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 ramble: We might find this adjacent file most useful!

// LoadEnvironmentVariables sets flags based on their environment variable value
func (c *Config) LoadEnvironmentVariables() error {

NoColor bool

// Feature experiments
Expand Down
1 change: 1 addition & 0 deletions internal/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (c *Config) InitializeGlobalFlags(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&c.DeprecatedDevFlag, "dev", "d", false, "use dev apis") // Can be removed after v0.25.0
cmd.PersistentFlags().StringVarP(&c.DeprecatedWorkspaceFlag, "workspace", "", "", "select workspace or organization by domain name or team ID")
cmd.PersistentFlags().StringSliceVarP(&c.ExperimentsFlag, "experiment", "e", nil, "use the experiment(s) in the command")
cmd.PersistentFlags().BoolVarP(&c.Accessible, "accessible", "", false, "use accessible prompts for screen readers")
cmd.PersistentFlags().BoolVarP(&c.ForceFlag, "force", "f", false, "ignore warnings and continue executing command")
cmd.PersistentFlags().BoolVarP(&c.NoColor, "no-color", "", false, "remove styles and formatting from outputs")
cmd.PersistentFlags().BoolVarP(&c.SkipUpdateFlag, "skip-update", "s", false, "skip checking for latest version of CLI")
Expand Down
3 changes: 3 additions & 0 deletions internal/iostreams/forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func newForm(io *IOStreams, field huh.Field) *huh.Form {
} else {
form = form.WithTheme(style.ThemeSurvey())
}
if io != nil && io.config.Accessible {
form = form.WithAccessible(true)
}
return form
}

Expand Down
48 changes: 48 additions & 0 deletions internal/iostreams/forms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,54 @@ func TestFormsUseSlackTheme(t *testing.T) {
})
}

func TestFormsAccessible(t *testing.T) {
fsMock := slackdeps.NewFsMock()
osMock := slackdeps.NewOsMock()
osMock.AddDefaultMocks()
cfg := config.NewConfig(fsMock, osMock)
cfg.Accessible = true
io := NewIOStreams(cfg, fsMock, osMock)

t.Run("select form accepts valid numbered input", func(t *testing.T) {
var selected string
f := buildSelectForm(io, "Pick one", []string{"A", "B", "C"}, SelectPromptConfig{}, &selected)

var out strings.Builder
err := f.WithOutput(&out).WithInput(strings.NewReader("2\n")).Run()

assert.NoError(t, err)
assert.Equal(t, "B", selected)
assert.Contains(t, out.String(), "1. A")
assert.Contains(t, out.String(), "2. B")
assert.Contains(t, out.String(), "3. C")
assert.Contains(t, out.String(), "Enter a number between 1 and 3")
})

t.Run("confirm form accepts yes/no input", func(t *testing.T) {
var choice bool
f := buildConfirmForm(io, "Continue?", &choice)

var out strings.Builder
err := f.WithOutput(&out).WithInput(strings.NewReader("y\n")).Run()

assert.NoError(t, err)
assert.True(t, choice)
assert.Contains(t, out.String(), "Continue?")
})

t.Run("input form accepts text input", func(t *testing.T) {
var input string
f := buildInputForm(io, "Name?", InputPromptConfig{}, &input)

var out strings.Builder
err := f.WithOutput(&out).WithInput(strings.NewReader("my-app\n")).Run()

assert.NoError(t, err)
assert.Equal(t, "my-app", input)
assert.Contains(t, out.String(), "Name?")
})
}

func TestFormsUseSurveyTheme(t *testing.T) {
t.Run("multi-select uses survey prefix without lipgloss", func(t *testing.T) {
var selected []string
Expand Down
Loading