Skip to content

Commit 134b3a7

Browse files
authored
feat: re-command, git flavoured (#21)
* feat: re-command, git flavoured * chore: update readme * chore: revert * fix: init alias to create
1 parent 6081005 commit 134b3a7

File tree

8 files changed

+56
-47
lines changed

8 files changed

+56
-47
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
## Usage
2121

22-
```bash
22+
```sh
2323
# global install
2424
npm i -g ghq-node
2525
$ ghq
@@ -28,22 +28,22 @@ $ ghq
2828
npx ghq-node
2929
```
3030

31-
```
31+
```console
3232
ghq/0.0.0
3333

3434
Usage:
3535
$ ghq <command> [options]
3636

3737
Commands:
38-
get [repo] Clone/sync with a remote repository
39-
create [repo] Create a new repository
40-
list [query] List local repositories
41-
config Manage the ghq configuration file
42-
root Alias to `ghq config --get.root`
38+
clone [repo] Clone/sync with a remote repository
39+
init [repo] Init a new repository
40+
list [query] List local repositories
41+
config Manage the ghq configuration file
42+
root Show repositories' root
4343

4444
For more info, run any command with the `--help` flag:
45-
$ ghq get --help
46-
$ ghq create --help
45+
$ ghq clone --help
46+
$ ghq init --help
4747
$ ghq list --help
4848
$ ghq config --help
4949
$ ghq root --help
@@ -55,9 +55,9 @@ Options:
5555

5656
## Directory
5757

58-
```
58+
```sh
5959
~
60-
├── .ghqrc
60+
├── .ghqrc # config file
6161
└── ghq
6262
└── github.com
6363
├── 2nthony

src/commands/get.ts renamed to src/commands/clone.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ import { parseCliOptionsToGitArgs } from "../args";
33
import { PluginApi } from "../types";
44
import { readConfig } from "../config";
55

6-
export const get: PluginApi = {
6+
export const cloneCommand: PluginApi = {
77
extend(api) {
88
api.cli
9-
.command("get [repo]", "Clone/sync with a remote repository")
10-
.alias("clone")
9+
.command("clone [repo]", "Clone/sync with a remote repository")
10+
.alias("get")
1111
.option("--shallow", "Shallow clone, alias to `--depth 1`", {
1212
default: false,
1313
type: [Boolean],
1414
})
15-
.example("ghq get 2nthony/ghq")
16-
.example("ghq get github.com/2nthony/ghq")
17-
.example("ghq get https://github.com/2nthony/ghq")
15+
.ignoreOptionDefaultValue()
1816
.example("ghq clone 2nthony/ghq")
17+
.example("ghq clone github.com/2nthony/ghq")
18+
.example("ghq clone https://github.com/2nthony/ghq")
19+
.example("ghq get 2nthony/ghq")
1920
.allowUnknownOptions()
2021
.action(async (repo, options) => {
2122
if (!repo) {

src/commands/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { PluginApi } from "../types";
1010
import { correctCliOptionsType } from "../args";
1111

12-
export const config: PluginApi = {
12+
export const configCommand: PluginApi = {
1313
extend(api) {
1414
const commandCli = api.cli
1515
.command("config", "Manage the ghq configuration file")

src/commands/create.ts

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

src/commands/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { get } from "./get";
2-
import { create } from "./create";
3-
import { list } from "./list";
4-
import { config } from "./config";
5-
import { root } from "./root";
1+
import { listCommand } from "./list";
2+
import { configCommand } from "./config";
3+
import { rootCommand } from "./root";
4+
import { cloneCommand } from "./clone";
5+
import { initCommand } from "./init";
66

7-
export const commands = [get, create, list, config, root];
7+
export const commands = [
8+
cloneCommand,
9+
initCommand,
10+
listCommand,
11+
configCommand,
12+
rootCommand,
13+
];

src/commands/init.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { init } from "../git";
2+
import { PluginApi } from "../types";
3+
4+
export const initCommand: PluginApi = {
5+
extend(api) {
6+
api.cli
7+
.command("init [repo]", "Init a new repository")
8+
.alias("create")
9+
.example("ghq init my-repo")
10+
.example("ghq init 2nthony/my-repo")
11+
.example("ghq init my-org/my-repo")
12+
.example("ghq init github.com/2nthony/my-repo")
13+
.example("ghq init https://github.com/2nthony/my-repo")
14+
.action((repo) => {
15+
if (!repo) {
16+
api.cli.outputHelp();
17+
return;
18+
}
19+
20+
init(repo);
21+
});
22+
},
23+
};

src/commands/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { collectDirs } from "../fs";
55
import { PathLike } from "fs";
66
import { resolveConfig } from "../config";
77

8-
export const list: PluginApi = {
8+
export const listCommand: PluginApi = {
99
extend(api) {
1010
api.cli
1111
.command("list [query]", "List local repositories")

src/commands/root.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resolveConfig } from "../config";
22
import { PluginApi } from "../types";
33

4-
export const root: PluginApi = {
4+
export const rootCommand: PluginApi = {
55
extend(api) {
66
api.cli.command("root", `Show repositories' root`).action(async () => {
77
const { root } = await resolveConfig();

0 commit comments

Comments
 (0)