Skip to content

Commit

Permalink
feat: print help without title for doc (#146)
Browse files Browse the repository at this point in the history
* feat: print help without title for doc

* feat: more help

* fix: recursive imports

* fix: dev help

* chore: fmt
  • Loading branch information
peterpeterparker authored Oct 30, 2024
1 parent 4206539 commit 576ff18
Show file tree
Hide file tree
Showing 20 changed files with 449 additions and 187 deletions.
4 changes: 2 additions & 2 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {red} from 'kleur';
import {logHelpDev} from '../help/dev.help';
import {build} from '../services/build.services';
import {start, stop} from '../services/docker.services';
import {eject} from '../services/eject.services';
import {helpDev} from './help';

export const dev = async (args?: string[]) => {
const [subCommand] = args ?? [];
Expand All @@ -22,6 +22,6 @@ export const dev = async (args?: string[]) => {
break;
default:
console.log(`${red('Unknown subcommand.')}`);
console.log(helpDev);
logHelpDev();
}
};
159 changes: 0 additions & 159 deletions src/commands/help.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/commands/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {nextArg} from '@junobuild/cli-tools';
import {red} from 'kleur';
import {logHelpUpgrade} from '../help/upgrade.help';
import {upgradeMissionControl} from '../services/upgrade/upgrade.mission-control.services';
import {upgradeOrbiters} from '../services/upgrade/upgrade.orbiter.services';
import {upgradeSatellite} from '../services/upgrade/upgrade.satellite.services';
import {helpUpgrade} from './help';

export const upgrade = async (args?: string[]) => {
const target = nextArg({args, option: '-t'}) ?? nextArg({args, option: '--target'});
Expand All @@ -23,6 +23,6 @@ export const upgrade = async (args?: string[]) => {
break;
default:
console.log(`${red('Unknown target.')}`);
console.log(helpUpgrade);
logHelpUpgrade();
}
};
31 changes: 31 additions & 0 deletions src/help/clear.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {cyan, green, yellow} from 'kleur';
import {helpMode, helpOutput} from './common.help';
import {TITLE} from './help';

export const CLEAR_DESCRIPTION =
'Clear existing dapp code by removing JavaScript, HTML, CSS, and other files from your satellite.';

const usage = `Usage: ${green('juno')} ${cyan('clear')} ${yellow('[options]')}
Options:
${yellow('-f, --fullPath')} Clear a particular file of your dapp.
${helpMode}
${yellow('-h, --help')} Output usage information.`;

const doc = `${CLEAR_DESCRIPTION}
\`\`\`bash
${usage}
\`\`\`
`;

const help = `${TITLE}
${CLEAR_DESCRIPTION}
${usage}
`;

export const logHelpClear = (args?: string[]) => {
console.log(helpOutput(args) === 'doc' ? doc : help);
};
7 changes: 7 additions & 0 deletions src/help/common.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {hasArgs} from '@junobuild/cli-tools';
import {yellow} from 'kleur';

export const helpMode = `${yellow('-m, --mode')} Set env mode. For example production or a custom string. Default is production.`;

export const helpOutput = (args?: string[]): 'doc' | 'cli' =>
hasArgs({args, options: ['-d', '--doc']}) ? 'doc' : 'cli';
29 changes: 29 additions & 0 deletions src/help/config.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {cyan, green, yellow} from 'kleur';
import {helpMode, helpOutput} from './common.help';
import {TITLE} from './help';

export const CONFIG_DESCRIPTION = 'Apply configuration to satellite.';

const usage = `Usage: ${green('juno')} ${cyan('config')} ${yellow('[options]')}
Options:
${helpMode}
${yellow('-h, --help')} Output usage information.`;

const doc = `${CONFIG_DESCRIPTION}
\`\`\`bash
${usage}
\`\`\`
`;

const help = `${TITLE}
${CONFIG_DESCRIPTION}
${usage}
`;

export const logHelpConfig = (args?: string[]) => {
console.log(helpOutput(args) === 'doc' ? doc : help);
};
30 changes: 30 additions & 0 deletions src/help/deploy.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {cyan, green, yellow} from 'kleur';
import {helpMode, helpOutput} from './common.help';
import {TITLE} from './help';

export const DEPLOY_DESCRIPTION = 'Deploy your dapp to your satellite.';

const usage = `Usage: ${green('juno')} ${cyan('deploy')} ${yellow('[options]')}
Options:
${yellow('-c, --clear')} Clear existing dapp files before proceeding with deployment.
${helpMode}
${yellow('-h, --help')} Output usage information.`;

const doc = `${DEPLOY_DESCRIPTION}
\`\`\`bash
${usage}
\`\`\`
`;

const help = `${TITLE}
${DEPLOY_DESCRIPTION}
${usage}
`;

export const logHelpDeploy = (args?: string[]) => {
console.log(helpOutput(args) === 'doc' ? doc : help);
};
42 changes: 42 additions & 0 deletions src/help/dev.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {cyan, green, magenta} from 'kleur';
import {helpOutput} from './common.help';
import {TITLE} from './help';

export const DEV_DESCRIPTION =
'Handle development-related tasks such as building and deploying locally using Cargo and Docker.';

const helpDevBuild = `${magenta('build')} Compile satellite features using Cargo.`;
const helpDevStart = `${magenta(
'start'
)} Start a local Internet Computer network, encapsulated in a Docker environment.`;

export const helpDevContinue = `${helpDevBuild}
${helpDevStart}`;

const usage = `Usage: ${green('juno')} ${cyan('dev')} ${magenta('<subcommand>')}
Subcommands:
${helpDevBuild}
${magenta(
'eject'
)} Create a Rust template for custom satellite feature hooks and extensions.
${helpDevStart}
${magenta('stop')} Stop the Docker environment.`;

const doc = `${DEV_DESCRIPTION}
\`\`\`bash
${usage}
\`\`\`
`;

const help = `${TITLE}
${DEV_DESCRIPTION}
${usage}
`;

export const logHelpDev = (args?: string[]) => {
console.log(helpOutput(args) === 'doc' ? doc : help);
};
Loading

0 comments on commit 576ff18

Please sign in to comment.