Created
January 10, 2020 10:47
-
-
Save MartinMuzatko/2922add0f84535a44f98a8e8fa729efa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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