Skip to content

Commit

Permalink
feat: print help without title for doc
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Oct 30, 2024
1 parent 4206539 commit dbd02d1
Show file tree
Hide file tree
Showing 15 changed files with 348 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();
}
};
28 changes: 28 additions & 0 deletions src/help/clear.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {cyan, green, yellow} from 'kleur';
import {helpMode, helpOutput, 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}
${usage}
`;

export const logHelpClear = (args?: string[]) => {
console.log(helpOutput(args) === 'doc' ? doc : help);
};
26 changes: 26 additions & 0 deletions src/help/config.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {cyan, green, yellow} from 'kleur';
import {helpMode, helpOutput, 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}
${usage}
`;

export const logHelpConfig = (args?: string[]) => {
console.log(helpOutput(args) === 'doc' ? doc : help);
};
27 changes: 27 additions & 0 deletions src/help/deploy.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {cyan, green, yellow} from 'kleur';
import {helpMode, helpOutput, 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}
${usage}
`;

export const logHelpDeploy = (args?: string[]) => {
console.log(helpOutput(args) === 'doc' ? doc : help);
};
39 changes: 39 additions & 0 deletions src/help/dev.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {cyan, green, magenta} from 'kleur';
import {helpOutput, 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}
${usage}
`;

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

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

const help = (command: string) => `${TITLE}
${usage(command)}
`;

const helpWithMode = (command: string) => `${TITLE}
${usage(command)}
${helpMode}
`;

const doc = (command: string) => `\`\`\`bash
${usage(command)}
\`\`\`
`;

const docWithMode = (command: string) => `\`\`\`bash
${usage(command)}
${helpMode}
\`\`\`
`;

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

export const logHelpWithMode = ({args, command}: {args?: string[]; command: string}) => {
console.log(helpOutput(args) === 'doc' ? docWithMode(command) : helpWithMode(command));
};
Loading

0 comments on commit dbd02d1

Please sign in to comment.