@tolgamorf/env2op-cli 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +72 -67
- package/src/cli.ts +30 -30
- package/src/commands/convert.ts +163 -168
- package/src/core/env-parser.ts +71 -70
- package/src/core/onepassword.ts +64 -71
- package/src/core/template-generator.ts +33 -32
- package/src/core/types.ts +56 -44
- package/src/index.ts +20 -22
- package/src/utils/errors.ts +59 -68
- package/src/utils/logger.ts +130 -130
package/src/utils/errors.ts
CHANGED
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
* Custom error class for env2op with error codes and suggestions
|
|
3
3
|
*/
|
|
4
4
|
export class Env2OpError extends Error {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
constructor(
|
|
6
|
+
message: string,
|
|
7
|
+
public code: ErrorCode,
|
|
8
|
+
public suggestion?: string,
|
|
9
|
+
) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "Env2OpError";
|
|
12
|
+
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Error codes for different failure scenarios
|
|
17
17
|
*/
|
|
18
18
|
export const ErrorCodes = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
ENV_FILE_NOT_FOUND: "ENV_FILE_NOT_FOUND",
|
|
20
|
+
ENV_FILE_EMPTY: "ENV_FILE_EMPTY",
|
|
21
|
+
OP_CLI_NOT_INSTALLED: "OP_CLI_NOT_INSTALLED",
|
|
22
|
+
OP_NOT_SIGNED_IN: "OP_NOT_SIGNED_IN",
|
|
23
|
+
VAULT_NOT_FOUND: "VAULT_NOT_FOUND",
|
|
24
|
+
VAULT_CREATE_FAILED: "VAULT_CREATE_FAILED",
|
|
25
|
+
ITEM_EXISTS: "ITEM_EXISTS",
|
|
26
|
+
ITEM_CREATE_FAILED: "ITEM_CREATE_FAILED",
|
|
27
|
+
PARSE_ERROR: "PARSE_ERROR",
|
|
28
28
|
} as const;
|
|
29
29
|
|
|
30
30
|
export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
@@ -33,63 +33,54 @@ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
|
33
33
|
* Error factory functions for common scenarios
|
|
34
34
|
*/
|
|
35
35
|
export const errors = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
envFileNotFound: (path: string) =>
|
|
37
|
+
new Env2OpError(
|
|
38
|
+
`File not found: ${path}`,
|
|
39
|
+
ErrorCodes.ENV_FILE_NOT_FOUND,
|
|
40
|
+
"Check that the file path is correct",
|
|
41
|
+
),
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
envFileEmpty: (path: string) =>
|
|
44
|
+
new Env2OpError(
|
|
45
|
+
`No valid environment variables found in ${path}`,
|
|
46
|
+
ErrorCodes.ENV_FILE_EMPTY,
|
|
47
|
+
"Ensure the file contains KEY=value pairs",
|
|
48
|
+
),
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
opCliNotInstalled: () =>
|
|
51
|
+
new Env2OpError(
|
|
52
|
+
"1Password CLI (op) is not installed",
|
|
53
|
+
ErrorCodes.OP_CLI_NOT_INSTALLED,
|
|
54
|
+
"Install it from https://1password.com/downloads/command-line/",
|
|
55
|
+
),
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
opNotSignedIn: () =>
|
|
58
|
+
new Env2OpError(
|
|
59
|
+
"Not signed in to 1Password CLI",
|
|
60
|
+
ErrorCodes.OP_NOT_SIGNED_IN,
|
|
61
|
+
'Run "op signin" to authenticate',
|
|
62
|
+
),
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
vaultNotFound: (vault: string) =>
|
|
65
|
+
new Env2OpError(
|
|
66
|
+
`Vault not found: ${vault}`,
|
|
67
|
+
ErrorCodes.VAULT_NOT_FOUND,
|
|
68
|
+
'Run "op vault list" to see available vaults',
|
|
69
|
+
),
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
`Failed to create vault: ${message}`,
|
|
74
|
-
ErrorCodes.VAULT_CREATE_FAILED,
|
|
75
|
-
),
|
|
71
|
+
vaultCreateFailed: (message: string) =>
|
|
72
|
+
new Env2OpError(`Failed to create vault: ${message}`, ErrorCodes.VAULT_CREATE_FAILED),
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
itemExists: (title: string, vault: string) =>
|
|
75
|
+
new Env2OpError(
|
|
76
|
+
`Item "${title}" already exists in vault "${vault}"`,
|
|
77
|
+
ErrorCodes.ITEM_EXISTS,
|
|
78
|
+
"Use default behavior (overwrites) or choose a different item name",
|
|
79
|
+
),
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
`Failed to create 1Password item: ${message}`,
|
|
87
|
-
ErrorCodes.ITEM_CREATE_FAILED,
|
|
88
|
-
),
|
|
81
|
+
itemCreateFailed: (message: string) =>
|
|
82
|
+
new Env2OpError(`Failed to create 1Password item: ${message}`, ErrorCodes.ITEM_CREATE_FAILED),
|
|
89
83
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
`Parse error at line ${line}: ${message}`,
|
|
93
|
-
ErrorCodes.PARSE_ERROR,
|
|
94
|
-
),
|
|
84
|
+
parseError: (line: number, message: string) =>
|
|
85
|
+
new Env2OpError(`Parse error at line ${line}: ${message}`, ErrorCodes.PARSE_ERROR),
|
|
95
86
|
};
|
package/src/utils/logger.ts
CHANGED
|
@@ -5,140 +5,140 @@ import pc from "picocolors";
|
|
|
5
5
|
* Unicode symbols for different message types
|
|
6
6
|
*/
|
|
7
7
|
const symbols = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
success: pc.green("\u2713"),
|
|
9
|
+
error: pc.red("\u2717"),
|
|
10
|
+
warning: pc.yellow("\u26A0"),
|
|
11
|
+
info: pc.blue("\u2139"),
|
|
12
|
+
arrow: pc.cyan("\u2192"),
|
|
13
|
+
bullet: pc.dim("\u2022"),
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Logger utility for formatted CLI output using @clack/prompts
|
|
18
18
|
*/
|
|
19
19
|
export const logger = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Display CLI intro banner
|
|
22
|
+
*/
|
|
23
|
+
intro(name: string, version: string, dryRun = false) {
|
|
24
|
+
const label = dryRun
|
|
25
|
+
? pc.bgYellow(pc.black(` ${name} v${version} [DRY RUN] `))
|
|
26
|
+
: pc.bgCyan(pc.black(` ${name} v${version} `));
|
|
27
|
+
p.intro(label);
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Display section header
|
|
32
|
+
*/
|
|
33
|
+
section(title: string) {
|
|
34
|
+
console.log(`\n${pc.bold(pc.underline(title))}`);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Success message
|
|
39
|
+
*/
|
|
40
|
+
success(message: string) {
|
|
41
|
+
p.log.success(message);
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Error message
|
|
46
|
+
*/
|
|
47
|
+
error(message: string) {
|
|
48
|
+
p.log.error(message);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Warning message
|
|
53
|
+
*/
|
|
54
|
+
warn(message: string) {
|
|
55
|
+
p.log.warn(message);
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Info message
|
|
60
|
+
*/
|
|
61
|
+
info(message: string) {
|
|
62
|
+
p.log.info(message);
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Step in a process
|
|
67
|
+
*/
|
|
68
|
+
step(message: string) {
|
|
69
|
+
p.log.step(message);
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Message (neutral)
|
|
74
|
+
*/
|
|
75
|
+
message(message: string) {
|
|
76
|
+
p.log.message(message);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Display key-value pair
|
|
81
|
+
*/
|
|
82
|
+
keyValue(key: string, value: string, indent = 2) {
|
|
83
|
+
console.log(`${" ".repeat(indent)}${pc.dim(key)}: ${pc.cyan(value)}`);
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Display list item
|
|
88
|
+
*/
|
|
89
|
+
listItem(item: string, indent = 2) {
|
|
90
|
+
console.log(`${" ".repeat(indent)}${symbols.bullet} ${item}`);
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Display arrow item
|
|
95
|
+
*/
|
|
96
|
+
arrowItem(item: string, indent = 2) {
|
|
97
|
+
console.log(`${" ".repeat(indent)}${symbols.arrow} ${item}`);
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Display dry run indicator
|
|
102
|
+
*/
|
|
103
|
+
dryRun(message: string) {
|
|
104
|
+
console.log(`${pc.yellow("[DRY RUN]")} ${message}`);
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Create a spinner for async operations
|
|
109
|
+
*/
|
|
110
|
+
spinner() {
|
|
111
|
+
return p.spinner();
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Display outro message
|
|
116
|
+
*/
|
|
117
|
+
outro(message: string) {
|
|
118
|
+
p.outro(pc.green(message));
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Display cancellation message
|
|
123
|
+
*/
|
|
124
|
+
cancel(message: string) {
|
|
125
|
+
p.cancel(message);
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Display a note block
|
|
130
|
+
*/
|
|
131
|
+
note(message: string, title?: string) {
|
|
132
|
+
p.note(message, title);
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Format a field list for display
|
|
137
|
+
*/
|
|
138
|
+
formatFields(fields: string[], max = 3): string {
|
|
139
|
+
if (fields.length <= max) {
|
|
140
|
+
return fields.join(", ");
|
|
141
|
+
}
|
|
142
|
+
return `${fields.slice(0, max).join(", ")}, ... and ${fields.length - max} more`;
|
|
143
|
+
},
|
|
144
144
|
};
|