Hey magical people!
Is there a way for me to merge 3 separete commander .command into 1 segment?
the way i have it now is:
friday
.command('init')
.description('Initialize friday')
.action(() => {
console.log(
chalk.yellow(
figlet.textSync('Friday', { horizontalLayout: 'full' })
)
);
});
friday
.command('github')
.description('ask for github credentials')
.action(async () => {
let token = github.getStoredGithubToken();
if (!token) {
await github.setGithubCredentials();
token = await github.registerNewToken();
}
console.log(token);
});
friday
.command('test')
.description('Create a new repository on github')
.action(async () => {
const getGithubToken = async () => {
// Fetch token from config store
let token = github.getStoredGithubToken();
if (token) {
return token;
}
// No token found, use credentials to access Github account
await setGithubCredentials();
// register new token
token = await github.registerNewToken();
return token;
}
try {
// Retrieve & set Auth token
const token = await getGithubToken();
github.githubAuth(token);
// Create remote repo
const url = await repo.createRemoteRepo();
// create gitignore file
await repo.createGitIgnore();
// set up local repo and push to remote
const done = await repo.setupRepo(url);
if (done) {
console.log(chalk.green('All done'));
}
} catch (error) {
if (error) {
switch (error.status) {
case 401:
console.log(chalk.red('Could\'t log you in. Please provide correct credentials or token.'));
break;
case 422:
console.log(chalk.red('There already exists a remote repository with the same name.'));
break;
default:
console.log(error);
break;
}
}
}
});
friday.parse(process.argv);
if (!friday.args.length) {
friday.help();
}
In the CLI it returns:
$ node friday.js
Usage: friday [options] [command]
Options:
-h, --help output usage information
Commands:
init Initialize friday
github ask for github credentials
test Create a new repository on github
Now how do i make it “merge” and as soon as i run node friday.js it not only initiates friday but it also ask for the github credentials ?