Skip to content

Commit bdc7398

Browse files
committed
feat: Fixed text wrapping which made it hard to copy the ssh key. Added static to fix message not displaying properly. Fixed progress not being displayed
1 parent 58a58db commit bdc7398

File tree

5 files changed

+145
-74
lines changed

5 files changed

+145
-74
lines changed

README.md

Lines changed: 126 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g codify
1818
$ codify COMMAND
1919
running command...
2020
$ codify (--version)
21-
codify/0.6.0 darwin-arm64 node-v20.15.1
21+
codify/0.7.0 darwin-arm64 node-v20.15.1
2222
$ codify --help [COMMAND]
2323
USAGE
2424
$ codify COMMAND
@@ -31,65 +31,89 @@ USAGE
3131
* [`codify destroy`](#codify-destroy)
3232
* [`codify help [COMMAND]`](#codify-help-command)
3333
* [`codify import`](#codify-import)
34+
* [`codify init`](#codify-init)
3435
* [`codify plan`](#codify-plan)
3536
* [`codify update [CHANNEL]`](#codify-update-channel)
3637

3738
## `codify apply`
3839

39-
Apply a codify file onto the system. A plan of the changes is first generated and a list of changes will be shown before proceeding
40+
Install or update resources on the system based on a codify.json file.
4041

4142
```
4243
USAGE
43-
$ codify apply [--json] [--debug] [-o plain|default|debug|json] [-s] [-p <value>]
44+
$ codify apply [--debug] [-o plain|default|json] [-p <value>] [-S <value>]
4445
4546
FLAGS
46-
-o, --output=<option> [default: default]
47-
<options: plain|default|debug|json>
48-
-p, --path=<value> Path to codify.json file
49-
-s, --secure
50-
--debug
51-
52-
GLOBAL FLAGS
53-
--json Format output as json.
47+
-S, --sudoPassword=<value> Automatically use this password for any commands that require elevated permissions.
48+
-o, --output=<option> [default: default] Control the output format.
49+
<options: plain|default|json>
50+
-p, --path=<value> Path to run Codify from.
51+
--debug Print additional debug logs.
5452
5553
DESCRIPTION
56-
Apply a codify file onto the system. A plan of the changes is first generated and a list of changes will be shown
57-
before proceeding
54+
Install or update resources on the system based on a codify.json file.
55+
56+
Codify first generates a plan to determine the necessary execution steps. See
57+
codify plan --help for more details.
58+
The execution plan will be presented and approval will be asked before Codify applies
59+
any changes.
60+
61+
For scripts: use --output json which will skip approval and
62+
apply changes directly.
63+
64+
For more information, visit: https://docs.codifycli.com/commands/apply
65+
5866
5967
EXAMPLES
6068
$ codify apply
6169
6270
$ codify apply --path ~
71+
72+
$ codify apply -o json
73+
74+
$ codify apply -S <sudo password>
6375
```
6476

65-
_See code: [src/commands/apply/index.ts](https://github.com/kevinwang5658/codify/blob/v0.6.0/src/commands/apply/index.ts)_
77+
_See code: [src/commands/apply.ts](https://github.com/kevinwang5658/codify/blob/v0.7.0/src/commands/apply.ts)_
6678

6779
## `codify destroy`
6880

69-
Destroy or uninstall a resource (or many resources).
81+
Use Codify to uninstall a supported package or setting on the system.
7082

7183
```
7284
USAGE
73-
$ codify destroy [--json] [--debug] [-o plain|default|debug|json] [-s] [-p <value>]
85+
$ codify destroy [--debug] [-o plain|default|json] [-p <value>] [-S <password>]
7486
7587
FLAGS
76-
-o, --output=<option> [default: default]
77-
<options: plain|default|debug|json>
78-
-p, --path=<value> Path to codify.json file
79-
-s, --secure
80-
--debug
81-
82-
GLOBAL FLAGS
83-
--json Format output as json.
88+
-S, --sudoPassword=<password> Automatically use this password for any commands that require elevated permissions.
89+
-o, --output=<option> [default: default] Control the output format.
90+
<options: plain|default|json>
91+
-p, --path=<value> Path to run Codify from.
92+
--debug Print additional debug logs.
8493
8594
DESCRIPTION
86-
Destroy or uninstall a resource (or many resources).
95+
Use Codify to uninstall a supported package or setting on the system.
96+
97+
This command will only work for resources with Codify support. This command
98+
can work with or without a codify.json file.
99+
100+
Modes:
101+
• If a codify.json file exists, destroy the resource specified in the Codify.json file
102+
with a matching type.
103+
• If a codify.json file doesn't exist, additional information may be asked to identify
104+
the specific resource to destroy.
105+
106+
For more information, visit: https://docs.codifycli.com/commands/destory
87107
88108
EXAMPLES
89109
$ codify destroy homebrew nvm
110+
111+
$ codify destroy homebrew nvm --path=~
112+
113+
$ codify destroy
90114
```
91115

92-
_See code: [src/commands/destroy.ts](https://github.com/kevinwang5658/codify/blob/v0.6.0/src/commands/destroy.ts)_
116+
_See code: [src/commands/destroy.ts](https://github.com/kevinwang5658/codify/blob/v0.7.0/src/commands/destroy.ts)_
93117

94118
## `codify help [COMMAND]`
95119

@@ -113,48 +137,50 @@ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.1
113137

114138
## `codify import`
115139

116-
Generate codify configs from already installed packages. Use a list of space separated arguments to specify the resource types to import. Leave blank to import all resource in an existing *.codify.json file.
140+
Generate Codify configurations from already installed packages.
117141

118142
```
119143
USAGE
120-
$ codify import [--json] [--debug] [-o plain|default|debug|json] [-s] [-p <value>]
144+
$ codify import [--debug] [-o plain|default|json] [-p <value>]
121145
122146
FLAGS
123-
-o, --output=<option> [default: default]
124-
<options: plain|default|debug|json>
125-
-p, --path=<value> Path to codify.json file
126-
-s, --secure
127-
--debug
128-
129-
GLOBAL FLAGS
130-
--json Format output as json.
147+
-o, --output=<option> [default: default] Control the output format.
148+
<options: plain|default|json>
149+
-p, --path=<value> Path to run Codify from.
150+
--debug Print additional debug logs.
131151
132152
DESCRIPTION
133-
Generate codify configs from already installed packages. Use a list of space separated arguments to specify the
134-
resource types to import. Leave blank to import all resource in an existing *.codify.json file.
153+
Generate Codify configurations from already installed packages.
154+
155+
Use a space-separated list of arguments to specify the resource types to import.
156+
If a codify.json file already exists, omit arguments to update the file to match the system.
135157
136158
Modes:
137-
1. No args: if no args are specified and an *.codify.json already exists. Then codify will update the existing file
138-
with any new changes to the resources specified in the file/files.
159+
1. No args: If no args are specified and an *.codify.json already exists, Codify
160+
will update the existing file with new changes on the system.
139161
140-
Command: codify import
162+
Command:
163+
codify import
141164
142-
2. With args: specify specific resources to import using arguments. Wild card matching is supported using '*' and ?
143-
(Note: in zsh * expands to the current dir and needs to be escaped using \* or '*'). A prompt will be shown if more
144-
information is required to complete the import.
165+
2. With args: Specify specific resources to import using arguments. Wild card matching is supported
166+
using '*' and '?' (Note: in zsh * expands to the current dir and needs to be escaped using \* or '*').
167+
A prompt will be shown if more information is required to complete the import.
145168
146-
Example: codify import nvm asdf\*, codify import \* (for importing all supported resources)
169+
Examples:
170+
codify import nvm asdf*
171+
codify import \* (for importing all supported resources)
147172
148-
The results can then be saved:
173+
The results can be saved in one of three ways:
149174
a. To an existing *.codify.json file
150175
b. To a new file
151-
c. Or only printed to console
176+
c. Printed to the console only
152177
153-
Codify will try to smartly insert new configs by following existing spacing and formatting.
178+
Codify will attempt to smartly insert new configurations while preserving existing spacing and formatting.
154179
180+
For more information, visit: https://docs.codifycli.com/commands/import
155181
156182
EXAMPLES
157-
$ codify import homebrew nvm asdf\*
183+
$ codify import homebrew nvm asdf
158184
159185
$ codify import
160186
@@ -163,35 +189,72 @@ EXAMPLES
163189
$ codify import \*
164190
```
165191

166-
_See code: [src/commands/import.ts](https://github.com/kevinwang5658/codify/blob/v0.6.0/src/commands/import.ts)_
192+
_See code: [src/commands/import.ts](https://github.com/kevinwang5658/codify/blob/v0.7.0/src/commands/import.ts)_
167193

168-
## `codify plan`
194+
## `codify init`
169195

170-
Generate a plan based on a codify.json file. This plan will list out the changes Codify will need to make in order to meet the desired config.
196+
A helper to quickly get started with Codify.
171197

172198
```
173199
USAGE
174-
$ codify plan [--json] [--debug] [-o plain|default|debug|json] [-s] [-p <value>]
200+
$ codify init [--debug] [-o plain|default|json]
175201
176202
FLAGS
177-
-o, --output=<option> [default: default]
178-
<options: plain|default|debug|json>
179-
-p, --path=<value> Path to codify.json file
180-
-s, --secure
181-
--debug
203+
-o, --output=<option> [default: default] Control the output format.
204+
<options: plain|default|json>
205+
--debug Print additional debug logs.
206+
207+
DESCRIPTION
208+
A helper to quickly get started with Codify.
182209
183-
GLOBAL FLAGS
184-
--json Format output as json.
210+
Use this command to automatically generate Codify configs based on
211+
the currently installed system resources. By default, the new file
212+
will be written to ~/codify.json .
213+
214+
For more information, visit: https://docs.codifycli.com/commands/init
215+
216+
EXAMPLES
217+
$ codify init
218+
```
219+
220+
_See code: [src/commands/init.ts](https://github.com/kevinwang5658/codify/blob/v0.7.0/src/commands/init.ts)_
221+
222+
## `codify plan`
223+
224+
Generate an execution plan to apply changes from a codify.json file.
225+
226+
```
227+
USAGE
228+
$ codify plan [--debug] [-o plain|default|json] [-p <value>]
229+
230+
FLAGS
231+
-o, --output=<option> [default: default] Control the output format.
232+
<options: plain|default|json>
233+
-p, --path=<value> Path to run Codify from.
234+
--debug Print additional debug logs.
185235
186236
DESCRIPTION
187-
Generate a plan based on a codify.json file. This plan will list out the changes Codify will need to make in order to
188-
meet the desired config.
237+
Generate an execution plan to apply changes from a codify.json file.
238+
239+
This plan lists all the changes Codify needs to make to apply the codify.json file.
240+
The plan will not be executed. Behind the scenes, Codify performs a refresh scan to
241+
determine the current configuration and installed resources, then compares them with
242+
the desired configuration to compute the execution plan.
243+
244+
For scripts: use --output json which will skip all prompts and print
245+
only the final result as a json.
246+
247+
For more information, visit: https://docs.codifycli.com/commands/plan
189248
190249
EXAMPLES
191250
$ codify plan
251+
252+
$ codify plan -o json
253+
254+
$ codify plan -p ../
192255
```
193256

194-
_See code: [src/commands/plan/index.ts](https://github.com/kevinwang5658/codify/blob/v0.6.0/src/commands/plan/index.ts)_
257+
_See code: [src/commands/plan.ts](https://github.com/kevinwang5658/codify/blob/v0.7.0/src/commands/plan.ts)_
195258

196259
## `codify update [CHANNEL]`
197260

codify.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
{ "type": "virtualenv" },
99
{ "type": "virtualenv-project", "dest": ".venv12", "cwd": "~/Projects/python-temp2", "automaticallyInstallRequirementsTxt": true },
10-
{ "type": "pnpm", "version": "9.15.5", "globalEnv": "20.15" },
10+
{ "type": "pnpm", "version": "9.15.5", "globalEnvNodeVersion": "20.15" },
1111
{ "type": "path", "path": "$HOME/.bun/bin"},
1212
{
1313
"type": "path",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"start:dev": "./bin/dev.js",
124124
"start:vm": "npm run build && npm run pack:macos && npm run start:vm"
125125
},
126-
"version": "0.6.0",
126+
"version": "0.7.0",
127127
"bugs": "https://github.com/kevinwang5658/codify/issues",
128128
"keywords": [
129129
"oclif"
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, Text, useInput } from 'ink';
1+
import { Box, Static, Text, useInput } from 'ink';
22
import React from 'react';
33

44
export function PromptPressKeyToContinue(props: {
@@ -9,9 +9,11 @@ export function PromptPressKeyToContinue(props: {
99
props.onInput();
1010
});
1111

12-
return <Box flexDirection='column' marginTop={1}>
13-
{ props.message && (<Text>{props.message}</Text>) }
14-
<Text> </Text>
15-
<Text color='gray' dimColor>{'<Press any key to continue>'}</Text>
16-
</Box>
12+
return <Static items={[{}]}>{
13+
(item, idx) => (<Box flexDirection='column' key={idx} marginTop={1}>
14+
{ props.message && (<Text wrap='middle'>{props.message}</Text>) }
15+
<Text> </Text>
16+
<Text color='gray' dimColor>{'<Press any key to continue>'}</Text>
17+
</Box>)
18+
}</Static>
1719
}

src/ui/reporters/default-reporter.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import React from 'react';
88
import { Plan } from '../../entities/plan.js';
99
import { ResourceConfig } from '../../entities/resource-config.js';
1010
import { ResourceInfo } from '../../entities/resource-info.js';
11-
import { ctx, Event, ProcessName, SubProcessName } from '../../events/context.js';
11+
import { Event, ProcessName, SubProcessName, ctx } from '../../events/context.js';
1212
import { ImportResult } from '../../orchestrators/import.js';
1313
import { FileModificationResult } from '../../utils/file-modification-calculator.js';
14+
import { sleep } from '../../utils/index.js';
1415
import { SudoUtils } from '../../utils/sudo.js';
1516
import { DefaultComponent } from '../components/default-component.js';
1617
import { ProgressState, ProgressStatus } from '../components/progress/progress-display.js';
1718
import { RenderStatus, store } from '../store/index.js';
1819
import { PromptType, RenderEvent, Reporter } from './reporter.js';
19-
import { sleep } from '../../utils/index.js';
2020

2121
const ProgressLabelMapping = {
2222
[ProcessName.APPLY]: 'Codify apply',
@@ -50,12 +50,14 @@ export class DefaultReporter implements Reporter {
5050
}
5151

5252
async promptPressKeyToContinue(message?: string): Promise<void> {
53+
const previousRenderState = this.getRenderState();
54+
5355
await this.updateStateAndAwaitEvent<boolean>(
5456
() => this.updateRenderState(RenderStatus.PROMPT_PRESS_KEY_TO_CONTINUE, message),
5557
RenderEvent.PROMPT_RESULT,
5658
)
5759

58-
this.updateRenderState(RenderStatus.NOTHING);
60+
this.updateRenderState(previousRenderState.status, previousRenderState.data);
5961
}
6062

6163
async displayInitBanner(): Promise<void> {
@@ -323,6 +325,10 @@ export class DefaultReporter implements Reporter {
323325
throw new Error('sudo: 3 incorrect password attempts')
324326
}
325327

328+
private getRenderState(): { status: RenderStatus, data: any } {
329+
return store.get(store.renderState) as { status: RenderStatus, data: any };
330+
}
331+
326332
private updateRenderState(status: RenderStatus | null, data?: unknown): void {
327333
store.set(store.renderState, { status, data });
328334
}

0 commit comments

Comments
 (0)