Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
saqqdy committed Mar 23, 2021
0 parents commit 10c4758
Show file tree
Hide file tree
Showing 5 changed files with 2,365 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const test = Deno.test;
export { parse } from 'https://deno.land/std/flags/mod.ts';
export { blue, bold, green, red, yellow } from 'https://deno.land/std/fmt/colors.ts';
export { assert, assertEquals, assertThrows, assertThrowsAsync } from 'https://deno.land/std/testing/asserts.ts';
77 changes: 77 additions & 0 deletions bin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import Denomander from 'https://deno.land/x/denomander/mod.ts';
import { blue, green, red } from './deps.ts';

const program = new Denomander({
app_name: 'My MY App',
app_description: 'My MY Description',
app_version: '1.0.1',
errors: {
INVALID_RULE: 'Invalid Rule',
OPTION_NOT_FOUND: 'Option not found!',
COMMAND_NOT_FOUND: 'Command not found!',
REQUIRED_OPTION_NOT_FOUND: 'Required option is not specified!',
REQUIRED_VALUE_NOT_FOUND: 'Required command value is not specified!',
TOO_MANY_PARAMS: 'You have passed too many parameters',
},
});

program.baseOption('-q --quiet', 'Do not output any message').globalOption('-c --color', 'Define the output color');

program
.command('serve', 'Start the server')
.alias('superserve', 'master-server')
.requiredOption('-p --port', 'Define the port')
.action(() => {
colored_output('http://localhost:' + program.port);
});

program
.command('clone [foldername]')
.action(({ foldername }: any) => {
colored_output('The repo is cloned into: ' + foldername);
})
.description('clone a repo');

program
.command('mv [from] [to] [message?]')
.action(({ from, to, message }: any) => {
colored_output(`File is moved from ${from} to ${to}`);
if (message) {
console.log(message);
}
})
.description('move file');

program.on('quiet', () => {
console.log('Enable Quiet Mode...');
});

try {
program.parse(Deno.args);
} catch (error) {
console.log(error);
}

function colored_output(text: string) {
if (program.color) {
switch (program.color) {
case 'red':
console.log(red(text));
break;

case 'green':
console.log(green(text));
break;

case 'blue':
console.log(blue(text));
break;

default:
console.log(text);
break;
}
} else {
console.log(text);
}
}
Loading

0 comments on commit 10c4758

Please sign in to comment.