Skip to content

Commit

Permalink
feat: Prefix and message are no longer demand options
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Oct 28, 2019
1 parent 668e46a commit 2448076
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
23 changes: 10 additions & 13 deletions bin/options.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
const yargs = require('yargs')
.usage(
`usage: git snapshot --prefix=<path> --branch=<branch> --message=<message> [--tag=<tag>] [--remote=<repository>] [--dry-run] [--cwd=<path>]`
`usage: git snapshot --branch=<branch> [--prefix=<path>] [--message=<commit message>] [--tag=<tag name>] [--remote=<repository url|remote name>] [--dry-run] [--cwd=<path>]`
)
.option('prefix', {
requiresArg: true,
alias: 'p',
describe: 'the name of the subdir to split out',
type: 'string',
group: 'Required'
})
.option('branch', {
requiresArg: true,
alias: 'b',
describe: 'the name of branch for split to',
type: 'string',
group: 'Required'
})
.option('prefix', {
requiresArg: true,
alias: 'p',
describe: 'the name of the subdir to split out',
type: 'string'
})
.option('message', {
requiresArg: true,
alias: 'm',
describe: 'commit message',
type: 'string',
group: 'Required'
type: 'string'
})
.option('author', {
requiresArg: true,
Expand Down Expand Up @@ -59,12 +57,11 @@ const yargs = require('yargs')
requiresArg: true,
alias: 'c',
describe: 'working directory',
type: 'string',
default: process.cwd()
type: 'string'
})
.alias('version', 'v')
.alias('help', 'h')
.demandOption(['prefix', 'message', 'branch']);
.demandOption(['branch']);

if (yargs.argv.debug) {
// Debug must be enabled before other requires in order to work
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const git = require('./lib/git');
* @param {Boolean} argv.debug output debugging information
*/
async function gitSnapshot(argv) {
const {prefix, branch, message, auther, force, tag, remote, dryRun, cwd} = {cwd: process.cwd(), ...argv};
// Apply default options
const {prefix, branch, message, auther, force, tag, remote, dryRun, cwd} = {cwd: process.cwd(), prefix: '.', ...argv};

if (argv.debug) {
// Debug must be enabled before other requires in order to work
Expand All @@ -37,6 +38,7 @@ async function gitSnapshot(argv) {
const onCwdOpts = {cwd};
const onWorktreeOpts = {cwd: worktreePath};
const autherOpt = auther ? ['--auther', auther] : [];
const messageOpt = message ? ['--message', message] : [];
const prefixPath = path.resolve(prefix);
const forceOpt = force ? '--force' : '';

Expand Down Expand Up @@ -107,7 +109,7 @@ async function gitSnapshot(argv) {
debug(`Commit files:`);
await git(['add', '-A', '--ignore-errors'], onWorktreeOpts);
await git(
['commit', '--amend', '--allow-empty', '--allow-empty-message', '-m', message].concat(autherOpt),
['commit', '--amend', '--allow-empty', '--allow-empty-message'].concat(messageOpt).concat(autherOpt),
onWorktreeOpts
);

Expand All @@ -125,6 +127,8 @@ async function gitSnapshot(argv) {
if (tag) {
await git(['push', forceOpt, remote, tag], onWorktreeOpts);
}
} else {
await git(['checkout', '-B', branch, workBranch], onWorktreeOpts);
}

// Completed successflly.
Expand Down

0 comments on commit 2448076

Please sign in to comment.