Skip to content

Instantly share code, notes, and snippets.

@MartinMuzatko
Created January 10, 2020 10:47
Show Gist options
  • Save MartinMuzatko/2922add0f84535a44f98a8e8fa729efa to your computer and use it in GitHub Desktop.
Save MartinMuzatko/2922add0f84535a44f98a8e8fa729efa to your computer and use it in GitHub Desktop.
const meow = require('meow')
const prop = k => o => o[k]
const pipe = (...fns) => x => [...fns].reduce((acc, f) => f(acc), x)
const siconstore = () => ({
cli: meow(`
Usage
$ siconstore [command]
Available Commands
$ siconstore publish
$ siconstore latest
`),
action: cli => cli.showHelp(),
})
siconstore.publish = () => ({
cli: meow(`
Usage
$ siconstore publish
Description
Uses stdin to publish json to app-store
`),
action: cli => {
console.log(cli.flags)
}
})
const getSubcommand = (cliObject, level) => pipe(
prop('input'),
prop(level),
name => prop(name)(cliObject),
)(prop('cli')(cliObject()))
const cli = (cliObject, level = 0) => {
const { cli: nextCli, action } = cliObject()
const subCommand = getSubcommand(cliObject, level)
return subCommand ?
cli(subCommand, level + 1) :
nextCli.flags.help ?
nextCli.showHelp() :
action(nextCli)
}
cli(siconstore)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment