Skip to content
This repository was archived by the owner on Jun 6, 2023. It is now read-only.

Commit 243398e

Browse files
committed
fix help bugs
1 parent b0fa428 commit 243398e

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

cli/index.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ for (var arg in argv) {
1919

2020
var givenNamespace = argv._[0];
2121
var givenName = argv._[1];
22-
if (givenNamespace === 'login') givenName = 'user';
23-
if (givenNamespace === 'logout') givenName = 'user';
22+
if (givenNamespace === 'login' || givenNamespace === 'logout') {
23+
if (givenName === 'help' || (givenName === 'user' && argv._[2] === 'help')) argv.help = true;
24+
givenName = 'user';
25+
}
2426

2527
// Packages
2628
var chalk = require('chalk');
@@ -66,15 +68,11 @@ function methodHints() {
6668
function versionStr() {
6769
return 'paperspace cli ' + module.exports.version;
6870
}
69-
if (givenNamespace === 'version' || ((argv.version === true || argv.v === true)) && givenNamespace === undefined) {
70-
console.log(versionStr());
71-
process.exit();
72-
}
7371

74-
if (!givenNamespace && !givenName) {
72+
function usage() {
7573
console.log(versionStr());
7674
console.log();
77-
console.log(' ' + chalk.bold('paperspace') + ' <namespace> <command> [...flags]');
75+
console.log(' ' + chalk.bold('paperspace') + ' <namespace> <command> [options...]');
7876
console.log();
7977
console.log(' ' + chalk.dim('Commands:'));
8078
console.log();
@@ -83,31 +81,48 @@ if (!givenNamespace && !givenName) {
8381
console.log(' ---');
8482
console.log(' ' + chalk.dim(DEETS_NOTE));
8583
console.log('');
84+
}
8685

86+
if (givenNamespace === 'version' || ((argv.version === true || argv.v === true)) && givenNamespace === undefined) {
87+
console.log(versionStr());
8788
process.exit();
8889
}
8990

90-
var foundMethod;
91+
if ((!givenNamespace && !givenName) || givenNamespace === 'help') {
92+
usage()
93+
process.exit();
94+
}
95+
96+
var foundMethod = false;
97+
var foundNamespace = false;
9198

9299
paperspace.eachEndpoint(function _each(namespace, name, method) {
93-
if (namespace === givenNamespace && name == givenName) {
94-
foundMethod = {
95-
namespace: namespace,
96-
name: name,
97-
method: method,
98-
};
100+
if (namespace === givenNamespace) {
101+
foundNamespace = true;
102+
if (name === givenName) {
103+
foundMethod = {
104+
namespace: namespace,
105+
name: name,
106+
method: method,
107+
};
108+
}
99109
}
100110
});
101111

102112
if (!foundMethod) {
103-
if (givenName === undefined) console.error('No such namespace: `' + givenNamespace + '`');
104-
else console.error('No such command: `' + givenNamespace + ' ' + givenName + '`');
113+
if (foundNamespace) {
114+
if (givenName === undefined) console.error('Error: no command provided for: `' + givenNamespace + '`');
115+
else console.error('Error: no such command: `' + givenNamespace + ' ' + givenName + '`');
116+
} else console.error('Error: no such namespace: `' + givenNamespace + '`');
105117
process.exit(1);
106118
}
107119

108-
if (argv.help && givenNamespace !== 'login') {
109-
console.log(methodHint(foundMethod));
110-
process.exit(1);
120+
if (argv.help || argv.h) {
121+
if (givenNamespace === 'login' || givenNamespace == 'logout') {
122+
console.log('Usage: paperspace login [[--email] <user@domain.com> [[--password] "<secretpw>" ]] [[--apiToken] "<name>"]]]');
123+
console.log(' paperspace logout');
124+
} else console.log(methodHint(foundMethod));
125+
process.exit();
111126
}
112127

113128
function safeJSON(obj) {

lib/method.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ function method(endpointSpec, methodParams, cb) {
7575
maybeAuthPassword = methodParams.authPassword || methodParams.password;
7676
maybeAuthAccessToken = methodParams.accessToken || methodParams.access_token;
7777
if (global.paperspace_cli) {
78-
if (methodParams.help || methodParams.h || methodParams['?'] || methodParams._[1] === 'help' || (methodParams._[1] === 'user' && methodParams._[2] === 'help')) {
79-
console.log('Usage: paperspace login [[--email] <user@domain.com> [[--password] "<secretpw>" ]] [--apiToken "<name>"]');
80-
process.exit(1);
81-
}
8278
if (!maybeAuthAccessToken) {
8379
// get positional email and password
8480
var i = 1;

0 commit comments

Comments
 (0)