Skip to content

Commit 3bef8da

Browse files
Merge pull request #19 from kevinwang5658/kevin/improved-error-handling
Kevin/improved error handling
2 parents 73744b2 + 1ae2e19 commit 3bef8da

31 files changed

Lines changed: 349 additions & 405 deletions

README.md

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ USAGE
2828
# Commands
2929
<!-- commands -->
3030
* [`codify apply [FILE]`](#codify-apply-file)
31-
* [`codify hello PERSON`](#codify-hello-person)
32-
* [`codify hello world`](#codify-hello-world)
3331
* [`codify help [COMMANDS]`](#codify-help-commands)
3432
* [`codify plan [FILE]`](#codify-plan-file)
3533
* [`codify plugins`](#codify-plugins)
@@ -41,21 +39,27 @@ USAGE
4139
* [`codify plugins:uninstall PLUGIN...`](#codify-pluginsuninstall-plugin-1)
4240
* [`codify plugins:uninstall PLUGIN...`](#codify-pluginsuninstall-plugin-2)
4341
* [`codify plugins update`](#codify-plugins-update)
44-
* [`codify uninstall [RESOURCE]`](#codify-uninstall-resource)
42+
* [`codify uninstall`](#codify-uninstall)
4543

4644
## `codify apply [FILE]`
4745

4846
describe the command here
4947

5048
```
5149
USAGE
52-
$ codify apply [FILE] [-p <value>]
50+
$ codify apply [FILE] [--json] [-o plain|default|debug|json] [--debug] [-p <value>]
5351
5452
ARGUMENTS
5553
FILE file to read
5654
5755
FLAGS
58-
-p, --path=<value> path to project
56+
-o, --output=<option> [default: default]
57+
<options: plain|default|debug|json>
58+
-p, --path=<value> path to project
59+
--debug
60+
61+
GLOBAL FLAGS
62+
--json Format output as json.
5963
6064
DESCRIPTION
6165
describe the command here
@@ -67,48 +71,6 @@ EXAMPLES
6771
_See
6872
code: [src/commands/apply/index.ts](https://github.com/kevinwang5658/codify/blob/v0.0.0/src/commands/apply/index.ts)_
6973

70-
## `codify hello PERSON`
71-
72-
Say hello
73-
74-
```
75-
USAGE
76-
$ codify hello PERSON -f <value>
77-
78-
ARGUMENTS
79-
PERSON Person to say hello to
80-
81-
FLAGS
82-
-f, --from=<value> (required) Who is saying hello
83-
84-
DESCRIPTION
85-
Say hello
86-
87-
EXAMPLES
88-
$ oex hello friend --from oclif
89-
hello friend from oclif! (./src/commands/hello/index.ts)
90-
```
91-
92-
_See code: [src/commands/hello/index.ts](https://github.com/kevinwang5658/codify/blob/v0.0.0/src/commands/hello/index.ts)_
93-
94-
## `codify hello world`
95-
96-
Say hello world
97-
98-
```
99-
USAGE
100-
$ codify hello world
101-
102-
DESCRIPTION
103-
Say hello world
104-
105-
EXAMPLES
106-
$ codify hello world
107-
hello world! (./src/commands/hello/world.ts)
108-
```
109-
110-
_See code: [src/commands/hello/world.ts](https://github.com/kevinwang5658/codify/blob/v0.0.0/src/commands/hello/world.ts)_
111-
11274
## `codify help [COMMANDS]`
11375

11476
Display help for codify.
@@ -135,15 +97,21 @@ describe the command here
13597

13698
```
13799
USAGE
138-
$ codify plan [FILE] [-f] [-n <value>] [-p <value>]
100+
$ codify plan [FILE] [--json] [-o plain|default|debug|json] [--debug] [-f] [-n <value>] [-p <value>]
139101
140102
ARGUMENTS
141103
FILE file to read
142104
143105
FLAGS
144106
-f, --force
145-
-n, --name=<value> name to print
146-
-p, --path=<value> path to project
107+
-n, --name=<value> name to print
108+
-o, --output=<option> [default: default]
109+
<options: plain|default|debug|json>
110+
-p, --path=<value> path to project
111+
--debug
112+
113+
GLOBAL FLAGS
114+
--json Format output as json.
147115
148116
DESCRIPTION
149117
describe the command here
@@ -402,16 +370,21 @@ DESCRIPTION
402370

403371
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.4/src/commands/plugins/update.ts)_
404372

405-
## `codify uninstall [RESOURCE]`
373+
## `codify uninstall`
406374

407375
describe the command here
408376

409377
```
410378
USAGE
411-
$ codify uninstall [RESOURCE]
379+
$ codify uninstall [--json] [-o plain|default|debug|json] [--debug]
412380
413-
ARGUMENTS
414-
RESOURCE resource type to uninstall
381+
FLAGS
382+
-o, --output=<option> [default: default]
383+
<options: plain|default|debug|json>
384+
--debug
385+
386+
GLOBAL FLAGS
387+
--json Format output as json.
415388
416389
DESCRIPTION
417390
describe the command here

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,45 @@
44
"codify": "./bin/run.js"
55
},
66
"dependencies": {
7+
"@inkjs/ui": "^1.0.0",
78
"@oclif/core": "^3",
89
"@oclif/plugin-help": "^5",
910
"@oclif/plugin-plugins": "^3.8.4",
10-
"semver": "^7.5.4",
11-
"codify-schemas": "1.0.32",
1211
"ajv": "^8.12.0",
1312
"ajv-formats": "^3.0.1",
14-
"tsx": "^4.7.3",
13+
"chalk": "^5.3.0",
14+
"codify-schemas": "1.0.32",
15+
"debug": "^4.3.4",
1516
"ink": "^4.4.1",
16-
"@inkjs/ui": "^1.0.0",
17+
"parse-json": "^8.1.0",
1718
"react": "^18.3.1",
18-
"chalk": "^5.3.0",
19-
"parse-json": "^8.1.0"
19+
"semver": "^7.5.4",
20+
"supports-color": "^9.4.0"
2021
},
2122
"description": "Codify is a set up as code tool for developers",
2223
"devDependencies": {
2324
"@oclif/prettier-config": "^0.2.1",
2425
"@oclif/test": "^3",
2526
"@types/chai": "^4",
2627
"@types/chai-as-promised": "^7.1.7",
28+
"@types/chalk": "^2.2.0",
29+
"@types/debug": "^4.1.12",
2730
"@types/mocha": "^9.0.0",
2831
"@types/mock-fs": "^4.13.3",
2932
"@types/node": "^18",
30-
"@types/semver": "^7.5.4",
3133
"@types/react": "^18.3.1",
32-
"@types/chalk": "^2.2.0",
33-
"eslint-config-prettier": "^9.0.0",
34+
"@types/semver": "^7.5.4",
3435
"chai": "^4",
3536
"chai-as-promised": "^7.1.1",
3637
"eslint": "^8.51.0",
3738
"eslint-config-oclif": "^5",
3839
"eslint-config-oclif-typescript": "^3",
40+
"eslint-config-prettier": "^9.0.0",
3941
"mocha": "^10",
4042
"mock-fs": "^5.2.0",
4143
"oclif": "^4.5.7",
4244
"shx": "^0.3.3",
43-
"ts-node": "^10.9.1",
45+
"tsx": "^4.7.3",
4446
"typescript": "^5",
4547
"vitest": "^1.4.0"
4648
},

src/commands/apply/index.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Args, Command, Flags } from '@oclif/core'
1+
import { Args, Flags } from '@oclif/core'
22
import { ResourceOperation } from 'codify-schemas';
3-
import path from 'node:path';
3+
import * as path from 'node:path';
44

55
import { ApplyOrchestrator } from '../../orchestrators/apply.js';
66
import { PlanOrchestrator } from '../../orchestrators/plan.js';
7-
import { DefaultReporter } from '../../ui/reporters/default-reporter.js';
7+
import { BaseCommand } from '../../common/base-command.js';
88

9-
export default class Apply extends Command {
9+
export default class Apply extends BaseCommand {
1010
static args = {
1111
file: Args.string({ description: 'file to read' }),
1212
}
@@ -24,36 +24,29 @@ export default class Apply extends Command {
2424

2525
public async run(): Promise<void> {
2626
const { flags } = await this.parse(Apply)
27-
const reporter = new DefaultReporter()
28-
29-
try {
30-
if (flags.path) {
31-
this.log(`Applying Codify from: ${flags.path}`);
32-
}
33-
34-
const resolvedPath = path.resolve(flags.path ?? '.');
35-
36-
const planResult = await PlanOrchestrator.run(resolvedPath, false);
37-
reporter.displayPlan(planResult.plan);
38-
39-
// Short circuit and exit if every change is NOOP
40-
if (planResult.plan.every((p) => p.operation === ResourceOperation.NOOP)) {
41-
console.log('No changes necessary. Exiting');
42-
await planResult.pluginCollection.destroy();
43-
return process.exit(0);
44-
}
45-
46-
const confirm = await reporter.promptApplyConfirmation()
47-
if (!confirm) {
48-
return process.exit(0);
49-
}
50-
51-
await ApplyOrchestrator.run(planResult);
52-
} catch (error: unknown) {
53-
console.error(error);
54-
process.exit(1);
27+
28+
if (flags.path) {
29+
this.log(`Applying Codify from: ${flags.path}`);
30+
}
31+
32+
const resolvedPath = path.resolve(flags.path ?? '.');
33+
34+
const planResult = await PlanOrchestrator.run(resolvedPath);
35+
this.reporter.displayPlan(planResult.plan);
36+
37+
// Short circuit and exit if every change is NOOP
38+
if (planResult.plan.every((p) => p.operation === ResourceOperation.NOOP)) {
39+
console.log('No changes necessary. Exiting');
40+
return process.exit(0);
41+
}
42+
43+
const confirm = await this.reporter.promptApplyConfirmation()
44+
if (!confirm) {
45+
return process.exit(0);
5546
}
5647

48+
await ApplyOrchestrator.run(planResult);
49+
5750
process.exit(0);
5851
}
5952
}

src/commands/hello/index.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/commands/hello/world.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/commands/plan/index.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Args, Command, Flags } from '@oclif/core'
1+
import { Args, Flags } from '@oclif/core'
22
import * as path from 'node:path';
33

44
import { PlanOrchestrator } from '../../orchestrators/plan.js';
5-
import { DefaultReporter } from '../../ui/reporters/default-reporter.js';
5+
import { BaseCommand } from '../../common/base-command.js';
66

7-
export default class Plan extends Command {
7+
export default class Plan extends BaseCommand {
88
static args = {
99
file: Args.string({ description: 'file to read' }),
1010
}
@@ -26,21 +26,15 @@ export default class Plan extends Command {
2626

2727
public async run(): Promise<void> {
2828
const { flags } = await this.parse(Plan)
29-
const reporter = new DefaultReporter()
3029

31-
try {
32-
if (flags.path) {
33-
this.log(`Applying Codify from: ${flags.path}`);
34-
}
35-
36-
const resolvedPath = path.resolve(flags.path ?? '.');
30+
if (flags.path) {
31+
this.log(`Applying Codify from: ${flags.path}`);
32+
}
3733

38-
const { plan } = await PlanOrchestrator.run(resolvedPath);
39-
reporter.displayPlan(plan);
34+
const resolvedPath = path.resolve(flags.path ?? '.');
4035

41-
} catch (error) {
42-
console.error(error);
43-
}
36+
const { plan } = await PlanOrchestrator.run(resolvedPath);
37+
this.reporter.displayPlan(plan);
4438

4539
process.exit(0);
4640
}

0 commit comments

Comments
 (0)