mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-21 09:51:58 +00:00
Sort 'balena help' primary commands in manually specified order
Connects-to: #1140 Change-type: patch Signed-off-by: Paulo Castro <paulo@balena.io>
This commit is contained in:
parent
c49a1d3fbf
commit
8f8d6b5f08
@ -19,6 +19,7 @@ capitano = require('capitano')
|
|||||||
columnify = require('columnify')
|
columnify = require('columnify')
|
||||||
|
|
||||||
messages = require('../utils/messages')
|
messages = require('../utils/messages')
|
||||||
|
{ getManualSortCompareFunction } = require('../utils/helpers')
|
||||||
{ exitWithExpectedError } = require('../utils/patterns')
|
{ exitWithExpectedError } = require('../utils/patterns')
|
||||||
{ getOclifHelpLinePairs } = require('./help_ts')
|
{ getOclifHelpLinePairs } = require('./help_ts')
|
||||||
|
|
||||||
@ -42,12 +43,30 @@ indent = (text) ->
|
|||||||
return ' ' + line
|
return ' ' + line
|
||||||
return text.join('\n')
|
return text.join('\n')
|
||||||
|
|
||||||
print = (usageDescriptionPairs...) ->
|
print = (usageDescriptionPairs) ->
|
||||||
data = _.fromPairs([].concat(usageDescriptionPairs...).sort())
|
console.log indent columnify _.fromPairs(usageDescriptionPairs),
|
||||||
console.log indent columnify data,
|
|
||||||
showHeaders: false
|
showHeaders: false
|
||||||
minWidth: 35
|
minWidth: 35
|
||||||
|
|
||||||
|
manuallySortedPrimaryCommands = [
|
||||||
|
'help',
|
||||||
|
'login',
|
||||||
|
'push',
|
||||||
|
'logs',
|
||||||
|
'ssh',
|
||||||
|
'apps',
|
||||||
|
'app',
|
||||||
|
'devices',
|
||||||
|
'device',
|
||||||
|
'tunnel',
|
||||||
|
'preload',
|
||||||
|
'build',
|
||||||
|
'deploy',
|
||||||
|
'join',
|
||||||
|
'leave',
|
||||||
|
'local scan',
|
||||||
|
]
|
||||||
|
|
||||||
general = (params, options, done) ->
|
general = (params, options, done) ->
|
||||||
console.log('Usage: balena [COMMAND] [OPTIONS]\n')
|
console.log('Usage: balena [COMMAND] [OPTIONS]\n')
|
||||||
console.log(messages.reachingOut)
|
console.log(messages.reachingOut)
|
||||||
@ -63,17 +82,21 @@ general = (params, options, done) ->
|
|||||||
return 'primary'
|
return 'primary'
|
||||||
return 'secondary'
|
return 'secondary'
|
||||||
|
|
||||||
print(parse(groupedCommands.primary))
|
print parse(groupedCommands.primary).sort(getManualSortCompareFunction(
|
||||||
|
manuallySortedPrimaryCommands,
|
||||||
|
([signature, description], manualItem) ->
|
||||||
|
signature == manualItem or signature.startsWith("#{manualItem} ")
|
||||||
|
))
|
||||||
|
|
||||||
if options.verbose
|
if options.verbose
|
||||||
console.log('\nAdditional commands:\n')
|
console.log('\nAdditional commands:\n')
|
||||||
print(parse(groupedCommands.secondary), getOclifHelpLinePairs())
|
print parse(groupedCommands.secondary).concat(getOclifHelpLinePairs()).sort()
|
||||||
else
|
else
|
||||||
console.log('\nRun `balena help --verbose` to list additional commands')
|
console.log('\nRun `balena help --verbose` to list additional commands')
|
||||||
|
|
||||||
if not _.isEmpty(capitano.state.globalOptions)
|
if not _.isEmpty(capitano.state.globalOptions)
|
||||||
console.log('\nGlobal Options:\n')
|
console.log('\nGlobal Options:\n')
|
||||||
print(parse(capitano.state.globalOptions))
|
print parse(capitano.state.globalOptions).sort()
|
||||||
|
|
||||||
return done()
|
return done()
|
||||||
|
|
||||||
@ -93,7 +116,7 @@ command = (params, options, done) ->
|
|||||||
|
|
||||||
if not _.isEmpty(command.options)
|
if not _.isEmpty(command.options)
|
||||||
console.log('\nOptions:\n')
|
console.log('\nOptions:\n')
|
||||||
print(parse(command.options))
|
print parse(command.options).sort()
|
||||||
|
|
||||||
return done()
|
return done()
|
||||||
|
|
||||||
|
@ -234,15 +234,15 @@ export function retry<T>(
|
|||||||
* compare(a, b) function will compare a and b using the standard '<' and
|
* compare(a, b) function will compare a and b using the standard '<' and
|
||||||
* '>' Javascript operators.
|
* '>' Javascript operators.
|
||||||
* - If only a or only b are found in the manuallySortedArray, the returned
|
* - If only a or only b are found in the manuallySortedArray, the returned
|
||||||
* compare(a, b) function will consider the found element as being
|
* compare(a, b) function will treat the element that was found as being
|
||||||
* "smaller than" the not-found element (i.e. found elements appeare before
|
* "smaller than" the not-found element (i.e. found elements appear before
|
||||||
* not-found elements in sorted order).
|
* not-found elements in sorted order).
|
||||||
*
|
*
|
||||||
* The equalityFunc() argument is a function used to compare the array items
|
* The equalityFunc(a, x) argument is a function used to compare the items
|
||||||
* against the manuallySortedArray. For example, if equalityFunc was (a, x) =>
|
* being sorted against the items in the manuallySortedArray. For example, if
|
||||||
* a.startsWith(x), where a is an item being sorted and x is an item in the
|
* equalityFunc was (a, x) => a.startsWith(x), where a is an item being sorted
|
||||||
* manuallySortedArray, then the manuallySortedArray could contain prefix
|
* and x is an item in the manuallySortedArray, then the manuallySortedArray
|
||||||
* substrings to guide the sorting.
|
* could contain prefix substrings to guide the sorting.
|
||||||
*
|
*
|
||||||
* @param manuallySortedArray A pre-sorted array to guide the sorting
|
* @param manuallySortedArray A pre-sorted array to guide the sorting
|
||||||
* @param equalityFunc An optional function used to compare the items being
|
* @param equalityFunc An optional function used to compare the items being
|
||||||
|
Loading…
x
Reference in New Issue
Block a user