-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·144 lines (123 loc) · 3.78 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
144
#!/usr/bin/env node
const { program } = require("commander");
const shell = require("shelljs");
const colors = require("colors");
const run = require("./main");
const store = require("data-store")("guc");
async function main() {
program
.name("git-ultimate-cloner")
.description("Smarter way to clone git repositories.")
.version("4.0.0");
program
.command("set-folder <folderName> <path>")
.description(
"Set a custom folder to clone into.To set default folder, use 'default' as folderName. Use quotes in path if it contains spaces."
)
.action((folderName, path) => {
if (!shell.test("-d", path)) {
console.log("Invalid path");
return;
}
if (folderName === "ide") {
console.log("Cannot name folder 'ide'.");
return;
}
if (folderName === "current") {
console.log("Cannot name folder 'current'.");
return;
}
store.set(folderName, path);
console.log("Set folder", folderName, path);
});
program
.command("delete-folder <folderName>")
.description("Delete a custom folder.")
.action((folderName) => {
if (store.has(folderName)) {
store.del(folderName);
console.log("Deleted folder", folderName);
} else {
console.log("Folder not found");
}
});
program
.command("list-folders")
.description("List all custom folders.")
.action(() => {
console.log(store.data);
});
program
.command("clear-folders")
.description("Clear all custom folders.")
.action(() => {
store.clear();
console.log("Cleared all folders");
});
program
.command("update-folder <folderName> <path>")
.description("Update a custom folder.")
.action((folderName, path) => {
if (!shell.test("-d", path)) {
console.log("Invalid path");
return;
}
if (folderName === "ide") {
console.log("Cannot name folder 'ide'.");
return;
}
if (folderName === "current") {
console.log("Cannot name folder 'current'.");
return;
}
if (store.has(folderName)) {
store.set(folderName, path);
console.log("Updated folder", folderName, path);
} else {
console.log("Folder not found");
}
});
program
.command("set-ide <ide>")
.description("Set the default ide to open the cloned repository in.")
.action((ide) => {
store.set("ide", ide);
console.log("Set ide", ide);
});
//add custom help
program.addHelpText(
"after",
`
Examples:
Cloning a repository into a custom folder:
$ guc clone <repo-url>
$ guc clone <repo-url> -f <folder-name>
$ guc clone <repo-url> -f current //clone into current folder
Cloning a repository into a custom folder and opening it in an editor:
NOTE: BY default, the editor is set to vscode.
$ guc clone <repo-url> -f <folder-name> -i <editor> //editors: vscode, atom, sublime
Setting a custom folder:
$ guc set-folder <folder-name> <path>
$ guc set-folder default <path> //to always clone into a particular folder
Deleting a custom folder:
$ guc delete-folder <folder-name>
Listing all custom folders:
$ guc list-folders
Clearing all custom folders:
$ guc clear-folders
Updating a custom folder:
$ guc update-folder <folder-name> <path>
Setting the default ide:
$ guc set-ide <ide> //editors: vscode, atom, sublime
`
);
program
.command("clone <url>")
.description("Clone a git repository.")
.option("-i, --ide <editor>", "Open the cloned repository in an editor.")
.option("-f, --folder <folder>", "Clone the repository into a folder.")
.action(run);
program.showHelpAfterError();
await program.parseAsync(process.argv);
}
main();