diff --git a/lib/actions/help.coffee b/lib/actions/help.coffee index c57fc765..503021aa 100644 --- a/lib/actions/help.coffee +++ b/lib/actions/help.coffee @@ -19,6 +19,7 @@ capitano = require('capitano') columnify = require('columnify') messages = require('../utils/messages') +{ getManualSortCompareFunction } = require('../utils/helpers') { exitWithExpectedError } = require('../utils/patterns') { getOclifHelpLinePairs } = require('./help_ts') @@ -42,12 +43,30 @@ indent = (text) -> return ' ' + line return text.join('\n') -print = (usageDescriptionPairs...) -> - data = _.fromPairs([].concat(usageDescriptionPairs...).sort()) - console.log indent columnify data, +print = (usageDescriptionPairs) -> + console.log indent columnify _.fromPairs(usageDescriptionPairs), showHeaders: false minWidth: 35 +manuallySortedPrimaryCommands = [ + 'help', + 'login', + 'push', + 'logs', + 'ssh', + 'apps', + 'app', + 'devices', + 'device', + 'tunnel', + 'preload', + 'build', + 'deploy', + 'join', + 'leave', + 'local scan', +] + general = (params, options, done) -> console.log('Usage: balena [COMMAND] [OPTIONS]\n') console.log(messages.reachingOut) @@ -63,17 +82,21 @@ general = (params, options, done) -> return 'primary' 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 console.log('\nAdditional commands:\n') - print(parse(groupedCommands.secondary), getOclifHelpLinePairs()) + print parse(groupedCommands.secondary).concat(getOclifHelpLinePairs()).sort() else console.log('\nRun `balena help --verbose` to list additional commands') if not _.isEmpty(capitano.state.globalOptions) console.log('\nGlobal Options:\n') - print(parse(capitano.state.globalOptions)) + print parse(capitano.state.globalOptions).sort() return done() @@ -93,7 +116,7 @@ command = (params, options, done) -> if not _.isEmpty(command.options) console.log('\nOptions:\n') - print(parse(command.options)) + print parse(command.options).sort() return done() diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index 7d0d96b7..beab4ba5 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -234,15 +234,15 @@ export function retry( * compare(a, b) function will compare a and b using the standard '<' and * '>' Javascript operators. * - If only a or only b are found in the manuallySortedArray, the returned - * compare(a, b) function will consider the found element as being - * "smaller than" the not-found element (i.e. found elements appeare before + * compare(a, b) function will treat the element that was found as being + * "smaller than" the not-found element (i.e. found elements appear before * not-found elements in sorted order). * - * The equalityFunc() argument is a function used to compare the array items - * against the manuallySortedArray. For example, if equalityFunc was (a, x) => - * a.startsWith(x), where a is an item being sorted and x is an item in the - * manuallySortedArray, then the manuallySortedArray could contain prefix - * substrings to guide the sorting. + * The equalityFunc(a, x) argument is a function used to compare the items + * being sorted against the items in the manuallySortedArray. For example, if + * equalityFunc was (a, x) => a.startsWith(x), where a is an item being sorted + * and x is an item in the manuallySortedArray, then the manuallySortedArray + * could contain prefix substrings 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