mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge pull request #7916 from oggy/descriptive-enums
Support descriptions for enum values in config.
This commit is contained in:
@@ -238,9 +238,13 @@ ScopeDescriptor = require './scope-descriptor'
|
||||
#
|
||||
# #### enum
|
||||
#
|
||||
# All types support an `enum` key. The enum key lets you specify all values
|
||||
# that the config setting can possibly be. `enum` _must_ be an array of values
|
||||
# of your specified type. Schema:
|
||||
# All types support an `enum` key, which lets you specify all the values the
|
||||
# setting can take. `enum` may be an array of allowed values (of the specified
|
||||
# type), or an array of objects with `value` and `description` properties, where
|
||||
# the `value` is an allowed value, and the `description` is a descriptive string
|
||||
# used in the settings view.
|
||||
#
|
||||
# In this example, the setting must be one of the 4 integers:
|
||||
#
|
||||
# ```coffee
|
||||
# config:
|
||||
@@ -250,6 +254,20 @@ ScopeDescriptor = require './scope-descriptor'
|
||||
# enum: [2, 4, 6, 8]
|
||||
# ```
|
||||
#
|
||||
# In this example, the setting must be either 'foo' or 'bar', which are
|
||||
# presented using the provided descriptions in the settings pane:
|
||||
#
|
||||
# ```coffee
|
||||
# config:
|
||||
# someSetting:
|
||||
# type: 'string'
|
||||
# default: 'foo'
|
||||
# enum: [
|
||||
# {value: 'foo', description: 'Foo mode. You want this.'}
|
||||
# {value: 'bar', description: 'Bar mode. Nobody wants that!'}
|
||||
# ]
|
||||
# ```
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# ```coffee
|
||||
@@ -1185,6 +1203,11 @@ Config.addSchemaEnforcers
|
||||
|
||||
validateEnum: (keyPath, value, schema) ->
|
||||
possibleValues = schema.enum
|
||||
|
||||
if Array.isArray(possibleValues)
|
||||
possibleValues = possibleValues.map (value) ->
|
||||
if value.hasOwnProperty('value') then value.value else value
|
||||
|
||||
return value unless possibleValues? and Array.isArray(possibleValues) and possibleValues.length
|
||||
|
||||
for possibleValue in possibleValues
|
||||
|
||||
Reference in New Issue
Block a user