Skip to content

Commit d6d57fb

Browse files
author
Chris Brody
authored
Merge pull request #109 from dlowder-salesforce/cli-noargs
Fix crash when no args passed in
2 parents b2417ca + 0030df7 commit d6d57fb

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

lib/cli-program.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ program
2222
opt.default
2323
));
2424

25-
program.parse(process.argv);
26-
27-
// TBD non-functional error handling code
28-
// FUTURE TODO: handle missing argument error in the right place
29-
// (see issue #48)
30-
// if (!program.args.length) {
31-
// program.help();
32-
// }
25+
const args = process.argv;
26+
if (args.length === 2) {
27+
args.push('--help');
28+
}
29+
program.parse(args);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`bin/cli.js with no arguments returns expected output 1`] = `
4+
"Usage: cli [options] <name>
5+
6+
creates a React Native library module for one or more platforms
7+
8+
Options:
9+
-V, --version output the version number
10+
--prefix [prefix] The prefix for the library module (default: \\"\\")
11+
--module-name [moduleName] The module library package name to be used in package.json. Default: react-native-(name in param-case)
12+
--module-prefix [modulePrefix] The module prefix for the library module, ignored if --module-name is specified (default: \\"react-native\\")
13+
--package-identifier [packageIdentifier] (Android only!) The package name for the Android module (default: \\"com.reactlibrary\\")
14+
--platforms <platforms> Platforms the library module will be created for - comma separated (default: \\"ios,android\\")
15+
--github-account [githubAccount] The github account where the library module is hosted (default: \\"github_account\\")
16+
--author-name [authorName] The author's name (default: \\"Your Name\\")
17+
--author-email [authorEmail] The author's email (default: \\"[email protected]\\")
18+
--license [license] The license type (default: \\"MIT\\")
19+
--view Generate the module as a very simple native view component
20+
--use-cocoapods Generate a library with a sample podspec and third party pod usage example
21+
--generate-example Generate an example project and links the library module to it, requires both react-native-cli and yarn to be installed globally
22+
--example-name [exampleName] Name for the example project (default: \\"example\\")
23+
--example-react-native-version [exampleReactNativeVersion] React Native version for the generated example project (default: \\"[email protected]\\")
24+
-h, --help output usage information"
25+
`;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const execa = require('execa');
2+
const path = require('path');
3+
4+
test('bin/cli.js with no arguments returns expected output', () => {
5+
// Test fix for issue #48
6+
return Promise.resolve(
7+
execa.command(`node ${path.resolve('bin/cli.js')}`)
8+
).then(
9+
({ stdout }) => {
10+
expect(stdout).toMatchSnapshot();
11+
}
12+
);
13+
});

0 commit comments

Comments
 (0)