Skip to content

Commit

Permalink
feat: re-command, git flavoured (#21)
Browse files Browse the repository at this point in the history
* feat: re-command, git flavoured

* chore: update readme

* chore: revert

* fix: init alias to create
  • Loading branch information
2nthony authored Jul 16, 2022
1 parent 6081005 commit 134b3a7
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 47 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

## Usage

```bash
```sh
# global install
npm i -g ghq-node
$ ghq
Expand All @@ -28,22 +28,22 @@ $ ghq
npx ghq-node
```

```
```console
ghq/0.0.0

Usage:
$ ghq <command> [options]

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

For more info, run any command with the `--help` flag:
$ ghq get --help
$ ghq create --help
$ ghq clone --help
$ ghq init --help
$ ghq list --help
$ ghq config --help
$ ghq root --help
Expand All @@ -55,9 +55,9 @@ Options:

## Directory

```
```sh
~
├── .ghqrc
├── .ghqrc # config file
└── ghq
└── github.com
├── 2nthony
Expand Down
13 changes: 7 additions & 6 deletions src/commands/get.ts → src/commands/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import { parseCliOptionsToGitArgs } from "../args";
import { PluginApi } from "../types";
import { readConfig } from "../config";

export const get: PluginApi = {
export const cloneCommand: PluginApi = {
extend(api) {
api.cli
.command("get [repo]", "Clone/sync with a remote repository")
.alias("clone")
.command("clone [repo]", "Clone/sync with a remote repository")
.alias("get")
.option("--shallow", "Shallow clone, alias to `--depth 1`", {
default: false,
type: [Boolean],
})
.example("ghq get 2nthony/ghq")
.example("ghq get github.com/2nthony/ghq")
.example("ghq get https://github.com/2nthony/ghq")
.ignoreOptionDefaultValue()
.example("ghq clone 2nthony/ghq")
.example("ghq clone github.com/2nthony/ghq")
.example("ghq clone https://github.com/2nthony/ghq")
.example("ghq get 2nthony/ghq")
.allowUnknownOptions()
.action(async (repo, options) => {
if (!repo) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { PluginApi } from "../types";
import { correctCliOptionsType } from "../args";

export const config: PluginApi = {
export const configCommand: PluginApi = {
extend(api) {
const commandCli = api.cli
.command("config", "Manage the ghq configuration file")
Expand Down
21 changes: 0 additions & 21 deletions src/commands/create.ts

This file was deleted.

18 changes: 12 additions & 6 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { get } from "./get";
import { create } from "./create";
import { list } from "./list";
import { config } from "./config";
import { root } from "./root";
import { listCommand } from "./list";
import { configCommand } from "./config";
import { rootCommand } from "./root";
import { cloneCommand } from "./clone";
import { initCommand } from "./init";

export const commands = [get, create, list, config, root];
export const commands = [
cloneCommand,
initCommand,
listCommand,
configCommand,
rootCommand,
];
23 changes: 23 additions & 0 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { init } from "../git";
import { PluginApi } from "../types";

export const initCommand: PluginApi = {
extend(api) {
api.cli
.command("init [repo]", "Init a new repository")
.alias("create")
.example("ghq init my-repo")
.example("ghq init 2nthony/my-repo")
.example("ghq init my-org/my-repo")
.example("ghq init github.com/2nthony/my-repo")
.example("ghq init https://github.com/2nthony/my-repo")
.action((repo) => {
if (!repo) {
api.cli.outputHelp();
return;
}

init(repo);
});
},
};
2 changes: 1 addition & 1 deletion src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { collectDirs } from "../fs";
import { PathLike } from "fs";
import { resolveConfig } from "../config";

export const list: PluginApi = {
export const listCommand: PluginApi = {
extend(api) {
api.cli
.command("list [query]", "List local repositories")
Expand Down
2 changes: 1 addition & 1 deletion src/commands/root.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolveConfig } from "../config";
import { PluginApi } from "../types";

export const root: PluginApi = {
export const rootCommand: PluginApi = {
extend(api) {
api.cli.command("root", `Show repositories' root`).action(async () => {
const { root } = await resolveConfig();
Expand Down

0 comments on commit 134b3a7

Please sign in to comment.