mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-18 14:44:23 +01:00
cli: print help instead of trace
Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
39
src/cli.js
39
src/cli.js
@@ -16,12 +16,14 @@ const { checkIfGitRepo } = require('./utils')
|
|||||||
const { remoteACL, share, remoteBranchProtectionRules, localACL, localBranchProtectionRules } = require('./cli-helpers')
|
const { remoteACL, share, remoteBranchProtectionRules, localACL, localBranchProtectionRules } = require('./cli-helpers')
|
||||||
|
|
||||||
const pkg = require('../package.json')
|
const pkg = require('../package.json')
|
||||||
program
|
|
||||||
.name('gitpear')
|
const gitPear = program
|
||||||
|
.name('git pear')
|
||||||
.description('CLI to gitpear')
|
.description('CLI to gitpear')
|
||||||
|
.usage('<command> [options]')
|
||||||
.version(pkg.version)
|
.version(pkg.version)
|
||||||
|
|
||||||
program
|
const commandInit = gitPear
|
||||||
.command('init')
|
.command('init')
|
||||||
.description('initialize a gitpear repo')
|
.description('initialize a gitpear repo')
|
||||||
.option('-s, --share [branch]', 'share the repo as public, default false, default branch is current', '')
|
.option('-s, --share [branch]', 'share the repo as public, default false, default branch is current', '')
|
||||||
@@ -60,7 +62,7 @@ program
|
|||||||
if (options.share) await share(name, branchToShare)
|
if (options.share) await share(name, branchToShare)
|
||||||
})
|
})
|
||||||
|
|
||||||
program
|
const commandShare = gitPear
|
||||||
.command('share')
|
.command('share')
|
||||||
.description('share a gitpear repo')
|
.description('share a gitpear repo')
|
||||||
.option('-b, --branch [b]', 'branch to share, default is current branch', '')
|
.option('-b, --branch [b]', 'branch to share, default is current branch', '')
|
||||||
@@ -80,7 +82,7 @@ program
|
|||||||
await share(name, branchToShare, options)
|
await share(name, branchToShare, options)
|
||||||
})
|
})
|
||||||
|
|
||||||
program
|
const commandACL = gitPear
|
||||||
.command('acl')
|
.command('acl')
|
||||||
.description('manage acl of a gitpear repo')
|
.description('manage acl of a gitpear repo')
|
||||||
.option('-u, --user', 'user to add/remove/list')
|
.option('-u, --user', 'user to add/remove/list')
|
||||||
@@ -89,13 +91,7 @@ program
|
|||||||
.addArgument(new commander.Argument('[a]', 'actiont to perform').choices(['add', 'remove', 'list']).default('list'))
|
.addArgument(new commander.Argument('[a]', 'actiont to perform').choices(['add', 'remove', 'list']).default('list'))
|
||||||
.addArgument(new commander.Argument('[n]', 'user or branch to add/remove/list').default(''))
|
.addArgument(new commander.Argument('[n]', 'user or branch to add/remove/list').default(''))
|
||||||
.action(async (a, n, options) => {
|
.action(async (a, n, options) => {
|
||||||
if (options.user && options.branch) {
|
if (options.user === options.branch) commandACL.help()
|
||||||
throw new Error('Cannot perform both user and branch action at the same time')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!options.user && !options.branch) {
|
|
||||||
throw new Error('Either user or branch option is required')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.user) {
|
if (options.user) {
|
||||||
if (options.path.startsWith('pear://')) {
|
if (options.path.startsWith('pear://')) {
|
||||||
@@ -113,7 +109,7 @@ program
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
program
|
const commandUnshare = gitPear
|
||||||
.command('unshare')
|
.command('unshare')
|
||||||
.description('unshare a gitpear repo')
|
.description('unshare a gitpear repo')
|
||||||
.option('-p, --path [path]', 'path to the repo', '.')
|
.option('-p, --path [path]', 'path to the repo', '.')
|
||||||
@@ -133,7 +129,7 @@ program
|
|||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
program
|
const commandList = gitPear
|
||||||
.command('list')
|
.command('list')
|
||||||
.description('list all gitpear repos')
|
.description('list all gitpear repos')
|
||||||
.addArgument(new commander.Argument('[u]', 'url to remote pear').default(''))
|
.addArgument(new commander.Argument('[u]', 'url to remote pear').default(''))
|
||||||
@@ -146,28 +142,21 @@ program
|
|||||||
home.list(s).forEach(n => console.log(n, ...(s ? ['\t', `pear://${k}/${n}`] : [])))
|
home.list(s).forEach(n => console.log(n, ...(s ? ['\t', `pear://${k}/${n}`] : [])))
|
||||||
})
|
})
|
||||||
|
|
||||||
program
|
const commandKey = gitPear
|
||||||
.command('key')
|
.command('key')
|
||||||
.description('get a public key of gitpear')
|
.description('get a public key of gitpear')
|
||||||
.action((p, options) => {
|
.action((p, options) => {
|
||||||
console.log('Public key:', home.readPk())
|
console.log('Public key:', home.readPk())
|
||||||
})
|
})
|
||||||
|
|
||||||
program
|
const commandDaemon = gitPear
|
||||||
.command('daemon')
|
.command('daemon')
|
||||||
.description('start/stop gitpear daemon')
|
.description('start/stop gitpear daemon')
|
||||||
.option('-s, --start', 'start daemon')
|
.option('-s, --start', 'start daemon')
|
||||||
.option('-k, --stop', 'stop daemon')
|
.option('-k, --stop', 'stop daemon')
|
||||||
.option('-a, --attach', 'watch daemon logs')
|
.option('-a, --attach', 'watch daemon logs')
|
||||||
.action((p, options) => {
|
.action((p, options) => {
|
||||||
if (options.opts().start && options.opts().stop) {
|
if (options.opts().start === options.opts().stop) commandDaemon.help()
|
||||||
console.error('Cannot start and stop daemon at the same time')
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
if (!options.opts().start && !options.opts().stop) {
|
|
||||||
console.error('Need either start or stop option')
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.opts().start) {
|
if (options.opts().start) {
|
||||||
if (home.getDaemonPid()) {
|
if (home.getDaemonPid()) {
|
||||||
@@ -207,4 +196,4 @@ program
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
program.parse()
|
gitPear.parse()
|
||||||
|
|||||||
Reference in New Issue
Block a user