gitshift 1.0.6 → 1.0.7
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 +1 -1
- package/src/commands/add.js +78 -67
package/package.json
CHANGED
package/src/commands/add.js
CHANGED
|
@@ -20,80 +20,91 @@ import {
|
|
|
20
20
|
} from "../utils/logger.js";
|
|
21
21
|
|
|
22
22
|
export async function addCommand() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (getProfile(name)) {
|
|
28
|
-
error(
|
|
29
|
-
`Profile "${name}" already exists`
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
process.exitCode = 1;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const username = await input({
|
|
37
|
-
message: "GitHub Username",
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const email = await input({
|
|
41
|
-
message: "Email",
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const createSSH = await confirm({
|
|
45
|
-
message:
|
|
46
|
-
"Generate SSH key automatically?",
|
|
47
|
-
default: true,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
let sshKey = null;
|
|
51
|
-
|
|
52
|
-
if (createSSH) {
|
|
53
|
-
const spinner = ora(
|
|
54
|
-
"Generating SSH key..."
|
|
55
|
-
).start();
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
sshKey = await generateSSHKey(
|
|
59
|
-
name,
|
|
60
|
-
email
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
spinner.succeed(
|
|
64
|
-
"SSH key generated"
|
|
65
|
-
);
|
|
66
|
-
} catch (err) {
|
|
67
|
-
spinner.fail(
|
|
68
|
-
"Unable to generate SSH key"
|
|
69
|
-
);
|
|
23
|
+
try {
|
|
24
|
+
const name = await input({
|
|
25
|
+
message: "Profile Name",
|
|
26
|
+
});
|
|
70
27
|
|
|
28
|
+
if (getProfile(name)) {
|
|
71
29
|
error(
|
|
72
|
-
"
|
|
30
|
+
`Profile "${name}" already exists`
|
|
73
31
|
);
|
|
74
32
|
|
|
75
|
-
if (
|
|
76
|
-
err &&
|
|
77
|
-
typeof err === "object" &&
|
|
78
|
-
"shortMessage" in err &&
|
|
79
|
-
err.shortMessage
|
|
80
|
-
) {
|
|
81
|
-
error(String(err.shortMessage));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
33
|
process.exitCode = 1;
|
|
85
34
|
return;
|
|
86
35
|
}
|
|
87
|
-
}
|
|
88
36
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
37
|
+
const username = await input({
|
|
38
|
+
message: "GitHub Username",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const email = await input({
|
|
42
|
+
message: "Email",
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const createSSH = await confirm({
|
|
46
|
+
message:
|
|
47
|
+
"Generate SSH key automatically?",
|
|
48
|
+
default: true,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
let sshKey = null;
|
|
52
|
+
|
|
53
|
+
if (createSSH) {
|
|
54
|
+
const spinner = ora(
|
|
55
|
+
"Generating SSH key..."
|
|
56
|
+
).start();
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
sshKey = await generateSSHKey(
|
|
60
|
+
name,
|
|
61
|
+
email
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
spinner.succeed(
|
|
65
|
+
"SSH key generated"
|
|
66
|
+
);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
spinner.fail(
|
|
69
|
+
"Unable to generate SSH key"
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
error(
|
|
73
|
+
"Could not create SSH key. Ensure OpenSSH is installed and available."
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
err &&
|
|
78
|
+
typeof err === "object" &&
|
|
79
|
+
"shortMessage" in err &&
|
|
80
|
+
err.shortMessage
|
|
81
|
+
) {
|
|
82
|
+
error(String(err.shortMessage));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
process.exitCode = 1;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
saveProfile({
|
|
91
|
+
name,
|
|
92
|
+
username,
|
|
93
|
+
email,
|
|
94
|
+
sshKey,
|
|
95
|
+
});
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
success(
|
|
98
|
+
`Profile "${name}" saved locally`
|
|
99
|
+
);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
if (err && err.name === "ExitPromptError") {
|
|
102
|
+
// User canceled the prompt (Ctrl+C / SIGINT). Exit gracefully.
|
|
103
|
+
process.exitCode = 0;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
error(String(err));
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
}
|
|
99
110
|
}
|