Skip to content

Commit

Permalink
Fix #4205 (step 6): Alias 'colour' for 'color'
Browse files Browse the repository at this point in the history
Allow the British English spelling of 'color' (colour) as aliases. Implemented at the command line for `--color`, `--stack-colors` and `stack ls stack-colors`. Implemented in yaml configuration files for `color:` and `stack-colors:` (in each case, the American spelling is the alternative that has priority).

The documentation in `yaml_configuration.md` is updated, accordingly.
  • Loading branch information
mpilgrem committed Aug 26, 2018
1 parent d341d50 commit 2d552c9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Other enhancements:
non-project-specific yaml configuration parameter, allows a stack user to
redefine the default styles that stack uses to color some of its output. See
`stack --help` for more information.
* British English spelling of 'color' (colour) accepted as an alias for
`--color`, `--stack-colors`, `stack ls stack-colors` at the command line and
for `color:` and `stack-colors:` in yaml configuration files.
* New build option `--ddump-dir`. (See [#4225](https://github.com/commercialhaskell/stack/issues/4225))

Bug fixes:
Expand Down
10 changes: 9 additions & 1 deletion doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,9 @@ The color use can also be set at the command line using the equivalent
`--color=<WHEN>` global option. Color use set at the command line takes
precedence over that set in a yaml configuration file.

(The British English spelling (colour) is also accepted. In yaml configuration
files, the American spelling is the alternative that has priority.)

### stack-colors

Stack uses styles to format some of its output. The default styles do not work
Expand Down Expand Up @@ -1053,4 +1056,9 @@ terminal theme might wish to set the styles as follows:
```yaml
stack-colors: error=31:good=32:shell=35:dir=34:recommendation=32:target=95:module=35:package-component=95
```
The styles can also be set at the command line using the equivalent `--stack-colors=<STYLES>` global option. Styles set at the command line take precedence over those set in a yaml configuration file.
The styles can also be set at the command line using the equivalent `--stack-colors=<STYLES>`
global option. Styles set at the command line take precedence over those set in
a yaml configuration file.

(The British English spelling (colour) is also accepted. In yaml configuration
files, the American spelling is the alternative that has priority.)
9 changes: 8 additions & 1 deletion src/Stack/Ls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ lsStylesCmd :: OA.Mod OA.CommandFields LsCmds
lsStylesCmd =
OA.command
"stack-colors"
(OA.info lsStylesOptsParser (OA.progDesc "View stack's output styles"))
(OA.info lsStylesOptsParser
(OA.progDesc "View stack's output styles"))
<>
OA.command
"stack-colours"
(OA.info lsStylesOptsParser
(OA.progDesc "View stack's output styles (alias for \
\'stack-colors')"))

data Snapshot = Snapshot
{ snapId :: Text
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Options/ConfigParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ configOptsParser currentDir hide0 =
hide)
<*> optionalFirst (option readColorWhen
( long "color"
<> long "colour"
<> metavar "WHEN"
<> completeWith ["always", "never", "auto"]
<> help "Specify when to use color in output; WHEN is 'always', \
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Options/GlobalParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ globalOptsParser currentDir kind defLogLevel =
hide <*>
option readStyles
(long "stack-colors" <>
long "stack-colours" <>
metavar "STYLES" <>
value mempty <>
help "Specify stack's output styles; STYLES is a colon-delimited \
Expand Down
18 changes: 16 additions & 2 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,16 @@ parseConfigMonoidObject rootDir obj = do
configMonoidSaveHackageCreds <- First <$> obj ..:? configMonoidSaveHackageCredsName
configMonoidHackageBaseUrl <- First <$> obj ..:? configMonoidHackageBaseUrlName
configMonoidIgnoreRevisionMismatch <- First <$> obj ..:? configMonoidIgnoreRevisionMismatchName
configMonoidColorWhen <- First <$> obj ..:? configMonoidColorWhenName
configMonoidStyles <- fromMaybe mempty <$> obj ..:? configMonoidStylesName

configMonoidColorWhenPrimary <- obj ..:? configMonoidColorWhenName
configMonoidColorWhenAlternative <- obj ..:? configMonoidColorWhenAlternativeName
let configMonoidColorWhen = First $ configMonoidColorWhenPrimary
<|> configMonoidColorWhenAlternative

configMonoidStylesPrimary <- obj ..:? configMonoidStylesName
configMonoidStylesAlternative <- obj ..:? configMonoidStylesAlternativeName
let configMonoidStyles = fromMaybe mempty $ configMonoidStylesPrimary
<|> configMonoidStylesAlternative

return ConfigMonoid {..}
where
Expand Down Expand Up @@ -1041,9 +1049,15 @@ configMonoidIgnoreRevisionMismatchName = "ignore-revision-mismatch"
configMonoidColorWhenName :: Text
configMonoidColorWhenName = "color"

configMonoidColorWhenAlternativeName :: Text
configMonoidColorWhenAlternativeName = "colour"

configMonoidStylesName :: Text
configMonoidStylesName = "stack-colors"

configMonoidStylesAlternativeName :: Text
configMonoidStylesAlternativeName = "stack-colours"

data ConfigException
= ParseConfigFileException (Path Abs File) ParseException
| ParseCustomSnapshotException Text ParseException
Expand Down

0 comments on commit 2d552c9

Please sign in to comment.