Skip to content

Commit c09343e

Browse files
committed
feat: improve cli experience
1 parent 37cf899 commit c09343e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/args.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { parseArgs } from "jsr:@std/cli@1.0.7/parse-args";
22
import type { Args } from "jsr:@std/cli@1.0.7/parse-args";
33
import { attemptToFindComposeFileInCurrentDir, exists } from "./utils/misc.ts";
44
import chalk from "chalk";
5+
const VERSION = '1.0.1';
56

67
export class Arguments {
78
public static parse(args: string[]): Args {
@@ -17,6 +18,7 @@ export class Arguments {
1718

1819
// And a list of aliases
1920
const alias = {
21+
"version": "v",
2022
"help": "h",
2123
"service": "s",
2224
"path": "p",
@@ -32,8 +34,8 @@ export class Arguments {
3234
}
3335

3436
public static printHelp(): void {
35-
console.log("Usage: dcmv [options]");
36-
console.log("Options:");
37+
console.log(`${chalk.blue('Usage:')} dcmv [options]`);
38+
console.log(chalk.blue("\nOptions:"));
3739
console.log(" --help, -h Print help");
3840
console.log(" --out Move service outside docker");
3941
console.log(" --in Move service inside docker");
@@ -42,11 +44,22 @@ export class Arguments {
4244
" --path, -p Absolute path to docker-compose.yml if compose file doesn't exist in pwd",
4345
);
4446
// Examples
45-
console.log("Examples:");
47+
console.log(chalk.blue("\nExamples:"));
4648
console.log("dcmv --out -s service1");
4749
}
4850

51+
public static printVersion(): void {
52+
console.log(`${chalk.blue('Version:')} ${chalk.green(VERSION)} \n`);
53+
}
54+
4955
public static validate(flags: Args) {
56+
// publish version if no argument passed
57+
if (Deno.args.length === 0) {
58+
Arguments.printVersion();
59+
Arguments.printHelp();
60+
Deno.exit(0);
61+
}
62+
5063
if (flags.path && !exists(flags.path)) {
5164
console.log(chalk.red(`\n Compose file ${flags.path} does not exist`));
5265
Deno.exit(0);
@@ -57,7 +70,7 @@ export class Arguments {
5770
if (!dcPath) {
5871
console.log(
5972
chalk.red(
60-
`\n Compose file not found in current directory. Pass -p compose_file_path`,
73+
`\n docker_compose.yml file not found in current directory. Pass -p compose_file_path`,
6174
),
6275
);
6376
Deno.exit(0);

src/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function main(): void {
1010
Arguments.printHelp();
1111
return;
1212
}
13+
if (flags.version) {
14+
Arguments.printVersion();
15+
return;
16+
}
1317

1418
Arguments.validate(flags);
1519

0 commit comments

Comments
 (0)