Skip to content

Commit

Permalink
Merge pull request #5 from atom-community/commands
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Jul 22, 2021
2 parents f66bf72 + db22f01 commit 69d9efd
Show file tree
Hide file tree
Showing 29 changed files with 80 additions and 94 deletions.
118 changes: 80 additions & 38 deletions src/apm-cli.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,83 @@ setupTempDirectory = ->

setupTempDirectory()

commandClasses = [
require './ci'
require './clean'
require './config'
require './dedupe'
require './develop'
require './disable'
require './docs'
require './enable'
require './featured'
require './init'
require './install'
require './links'
require './link'
require './list'
require './login'
require './publish'
require './rebuild'
require './rebuild-module-cache'
require './search'
require './star'
require './stars'
require './test'
require './uninstall'
require './unlink'
require './unpublish'
require './unstar'
require './upgrade'
require './view'
]

commands = {}
for commandClass in commandClasses
for name in commandClass.commandNames ? []
commands[name] = commandClass
ciClass = -> require './ci'
cleanClass = -> require './clean'
configClass = -> require './config'
dedupClass = -> require './dedupe'
developClass = -> require './develop'
disableClass = -> require './disable'
docsClass = -> require './docs'
enableClass = -> require './enable'
featuredClass = -> require './featured'
initClass = -> require './init'
installClass = -> require './install'
linksClass = -> require './links'
linkClass = -> require './link'
listClass = -> require './list'
loginClass = -> require './login'
publishClass = -> require './publish'
rebuildClass = -> require './rebuild'
rebuildModuleCacheClass = -> require './rebuild-module-cache'
searchClass = -> require './search'
starClass = -> require './star'
starsClass = -> require './stars'
testClass = -> require './test'
uninstallClass = -> require './uninstall'
unlinkClass = -> require './unlink'
unpublishClass = -> require './unpublish'
unstarClass = -> require './unstar'
upgradeClass = -> require './upgrade'
viewClass = -> require './view'

commands = {
'ci': ciClass,
'clean': cleanClass,
'prune': cleanClass,
'config': configClass,
'dedupe': dedupClass,
'dev': developClass,
'develop': developClass,
'disable': disableClass,
'docs': docsClass,
'home': docsClass,
'open': docsClass,
'enable': enableClass
'featured': featuredClass
'init': initClass,
'install': installClass,
'i': installClass,
'link': linkClass,
'ln': linkClass
'linked': linksClass,
'links': linksClass,
'lns': linksClass,
'list': listClass,
'ls': listClass,
'login': loginClass,
'publish': publishClass,
'rebuild-module-cache': rebuildModuleCacheClass,
'rebuild': rebuildClass,
'search': searchClass,
'star': starClass,
'stars': starsClass,
'starred': starsClass
'test': testClass
'deinstall': uninstallClass,
'delete': uninstallClass,
'erase': uninstallClass,
'remove': uninstallClass,
'rm': uninstallClass,
'uninstall': uninstallClass,
'unlink': unlinkClass,
'unpublish': unpublishClass,
'unstar': unstarClass,
'upgrade': upgradeClass,
'outdated': upgradeClass,
'update': upgradeClass,
'view': viewClass,
'show': viewClass,
}

parseOptions = (args=[]) ->
options = yargs(args).wrap(Math.min(100, yargs.terminalWidth()))
Expand Down Expand Up @@ -198,19 +240,19 @@ module.exports =
if args.version
printVersions(args, options.callback)
else if args.help
if Command = commands[options.command]
if Command = commands[options.command]?()
showHelp(new Command().parseOptions?(options.command))
else
showHelp(options)
options.callback()
else if command
if command is 'help'
if Command = commands[options.commandArgs]
if Command = commands[options.commandArgs]?()
showHelp(new Command().parseOptions?(options.commandArgs))
else
showHelp(options)
options.callback()
else if Command = commands[command]
else if Command = commands[command]?()
new Command().run(options)
else
options.callback("Unrecognized command: #{command}")
Expand Down
2 changes: 0 additions & 2 deletions src/ci.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Command = require './command'

module.exports =
class Ci extends Command
@commandNames: ['ci']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/clean.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ fs = require './fs'

module.exports =
class Clean extends Command
@commandNames: ['clean', 'prune']

constructor: ->
super()
@atomNpmPath = require.resolve('npm/bin/npm-cli')
Expand Down
2 changes: 0 additions & 2 deletions src/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Command = require './command'

module.exports =
class Config extends Command
@commandNames: ['config']

constructor: ->
super()
atomDirectory = apm.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/dedupe.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ fs = require './fs'

module.exports =
class Dedupe extends Command
@commandNames: ['dedupe']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/develop.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ request = require './request'

module.exports =
class Develop extends Command
@commandNames: ['dev', 'develop']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/disable.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ List = require './list'

module.exports =
class Disable extends Command
@commandNames: ['disable']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/docs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ config = require './apm'

module.exports =
class Docs extends View
@commandNames: ['docs', 'home', 'open']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/enable.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Command = require './command'

module.exports =
class Enable extends Command
@commandNames: ['enable']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/featured.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ tree = require './tree'

module.exports =
class Featured extends Command
@commandNames: ['featured']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/init.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ fs = require './fs'

module.exports =
class Init extends Command
@commandNames: ['init']

supportedSyntaxes: ['coffeescript', 'javascript']

parseOptions: (argv) ->
Expand Down
2 changes: 0 additions & 2 deletions src/install.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ request = require './request'

module.exports =
class Install extends Command
@commandNames: ['install', 'i']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/link.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ fs = require './fs'

module.exports =
class Link extends Command
@commandNames: ['link', 'ln']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/links.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ tree = require './tree'

module.exports =
class Links extends Command
@commandNames: ['linked', 'links', 'lns']

constructor: ->
super()
@devPackagesPath = path.join(config.getAtomDirectory(), 'dev', 'packages')
Expand Down
2 changes: 0 additions & 2 deletions src/list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ tree = require './tree'

module.exports =
class List extends Command
@commandNames: ['list', 'ls']

constructor: ->
super()
@userPackagesDirectory = path.join(config.getAtomDirectory(), 'packages')
Expand Down
2 changes: 0 additions & 2 deletions src/login.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class Login extends Command
else
callback(null, token)

@commandNames: ['login']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))

Expand Down
2 changes: 0 additions & 2 deletions src/publish.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ request = require './request'

module.exports =
class Publish extends Command
@commandNames: ['publish']

constructor: ->
super()
@userConfigPath = config.getUserConfigPath()
Expand Down
2 changes: 0 additions & 2 deletions src/rebuild-module-cache.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ fs = require './fs'

module.exports =
class RebuildModuleCache extends Command
@commandNames: ['rebuild-module-cache']

constructor: ->
super()
@atomPackagesDirectory = path.join(config.getAtomDirectory(), 'packages')
Expand Down
2 changes: 0 additions & 2 deletions src/rebuild.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Install = require './install'

module.exports =
class Rebuild extends Command
@commandNames: ['rebuild']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/search.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ tree = require './tree'

module.exports =
class Search extends Command
@commandNames: ['search']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/star.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ request = require './request'

module.exports =
class Star extends Command
@commandNames: ['star']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/stars.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ tree = require './tree'

module.exports =
class Stars extends Command
@commandNames: ['stars', 'starred']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ fs = require './fs'

module.exports =
class Test extends Command
@commandNames: ['test']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))

Expand Down
2 changes: 0 additions & 2 deletions src/uninstall.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ request = require './request'

module.exports =
class Uninstall extends Command
@commandNames: ['deinstall', 'delete', 'erase', 'remove', 'rm', 'uninstall']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/unlink.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ fs = require './fs'

module.exports =
class Unlink extends Command
@commandNames: ['unlink']

constructor: ->
super()
@devPackagesPath = path.join(config.getAtomDirectory(), 'dev', 'packages')
Expand Down
2 changes: 0 additions & 2 deletions src/unpublish.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ request = require './request'

module.exports =
class Unpublish extends Command
@commandNames: ['unpublish']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))

Expand Down
2 changes: 0 additions & 2 deletions src/unstar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ request = require './request'

module.exports =
class Unstar extends Command
@commandNames: ['unstar']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down
2 changes: 0 additions & 2 deletions src/upgrade.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ git = require './git'

module.exports =
class Upgrade extends Command
@commandNames: ['upgrade', 'outdated', 'update']

constructor: ->
super()
@atomDirectory = config.getAtomDirectory()
Expand Down
2 changes: 0 additions & 2 deletions src/view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ tree = require './tree'

module.exports =
class View extends Command
@commandNames: ['view', 'show']

parseOptions: (argv) ->
options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage """
Expand Down

0 comments on commit 69d9efd

Please sign in to comment.