mirror of
https://github.com/daveberrys/guh.git
synced 2026-11-29 00:26:46 +08:00
organize file system, update docs
This commit is contained in:
1 parent
932823fdde
commit
7a71d0e89d
21 files changed
+293
-256
No files matched your search
@@ -1,5 +1,32 @@
|
|||||||
# guh CLI — Command Reference
|
# guh CLI — Command Reference
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
- [`guh`](#guh)
|
||||||
|
- [`account`](#account)
|
||||||
|
- [`account save`](#account-save)
|
||||||
|
- [`account switch`](#account-switch)
|
||||||
|
- [`branch`](#branch)
|
||||||
|
- [`branch create`](#branch-create)
|
||||||
|
- [`branch switch`](#branch-switch)
|
||||||
|
- [`branch rename`](#branch-rename)
|
||||||
|
- [`browse`](#browse)
|
||||||
|
- [`browse issues`](#browse-issues)
|
||||||
|
- [`browse pr`](#browse-pr)
|
||||||
|
- [`commit`](#commit)
|
||||||
|
- [`diff`](#diff)
|
||||||
|
- [`init`](#init)
|
||||||
|
- [`link`](#link)
|
||||||
|
- [`link add`](#link-add)
|
||||||
|
- [`link remove`](#link-remove)
|
||||||
|
- [`logs`](#logs)
|
||||||
|
- [`pull`](#pull)
|
||||||
|
- [`push`](#push)
|
||||||
|
- [`stash`](#stash)
|
||||||
|
- [`undo`](#undo)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## `guh`
|
## `guh`
|
||||||
|
|
||||||
Root command. Prints a welcome message when run without a subcommand.
|
Root command. Prints a welcome message when run without a subcommand.
|
||||||
@@ -11,6 +38,65 @@ guh
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## `account`
|
||||||
|
|
||||||
|
### `account save`
|
||||||
|
|
||||||
|
Save a new account with username, email, classic token, and platform.
|
||||||
|
|
||||||
|
```
|
||||||
|
guh account save <username> <email> <classicToken> <platform>
|
||||||
|
```
|
||||||
|
|
||||||
|
All four values are required and must be non-empty. `platform` is the Git provider domain (e.g. `github.com`). Credentials are stored in the user config directory under `dev.pages.codedave.guh/accounts.json`.
|
||||||
|
|
||||||
|
### `account switch`
|
||||||
|
|
||||||
|
Switch to a saved account (updates global git config and credentials).
|
||||||
|
|
||||||
|
```
|
||||||
|
guh account switch <username>
|
||||||
|
```
|
||||||
|
|
||||||
|
Sets `credential.helper` to `store`, updates `user.name` and `user.email` in global git config, and overwrites `~/.git-credentials` with the stored token. The account must have been saved with `guh account save` first.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## `branch`
|
||||||
|
|
||||||
|
### `branch create`
|
||||||
|
|
||||||
|
Create and switch to a new branch.
|
||||||
|
|
||||||
|
```
|
||||||
|
guh branch create <name>
|
||||||
|
```
|
||||||
|
|
||||||
|
Equivalent to `git switch -c <name>`.
|
||||||
|
|
||||||
|
### `branch switch`
|
||||||
|
|
||||||
|
Switch to an existing branch, or list branches.
|
||||||
|
|
||||||
|
```
|
||||||
|
guh branch switch <name>
|
||||||
|
guh branch switch list
|
||||||
|
```
|
||||||
|
|
||||||
|
Equivalent to `git switch <name>`. Using `list` is equivalent to `git branch`.
|
||||||
|
|
||||||
|
### `branch rename`
|
||||||
|
|
||||||
|
Rename the current branch.
|
||||||
|
|
||||||
|
```
|
||||||
|
guh branch rename <name>
|
||||||
|
```
|
||||||
|
|
||||||
|
Equivalent to `git branch -m <name>`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## `browse`
|
## `browse`
|
||||||
|
|
||||||
Open the repository's remote origin in the default browser.
|
Open the repository's remote origin in the default browser.
|
||||||
@@ -21,7 +107,7 @@ guh browse
|
|||||||
|
|
||||||
Equivalent to opening the repo URL (without `.git` suffix) in a browser.
|
Equivalent to opening the repo URL (without `.git` suffix) in a browser.
|
||||||
|
|
||||||
### `issues`
|
### `browse issues`
|
||||||
|
|
||||||
Open the issues page.
|
Open the issues page.
|
||||||
|
|
||||||
@@ -29,7 +115,7 @@ Open the issues page.
|
|||||||
guh browse issues
|
guh browse issues
|
||||||
```
|
```
|
||||||
|
|
||||||
### `pr`
|
### `browse pr`
|
||||||
|
|
||||||
Open the pull requests page.
|
Open the pull requests page.
|
||||||
|
|
||||||
@@ -45,7 +131,6 @@ guh browse pr print
|
|||||||
guh browse print
|
guh browse print
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## `commit`
|
## `commit`
|
||||||
@@ -77,30 +162,6 @@ guh commit '["file1"]' "message" "description" push "all" # commit + push
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## `create`
|
|
||||||
|
|
||||||
### `branch`
|
|
||||||
|
|
||||||
Create and switch to a new branch.
|
|
||||||
|
|
||||||
```
|
|
||||||
guh create branch <branch>
|
|
||||||
```
|
|
||||||
|
|
||||||
Equivalent to `git switch -c <branch>`.
|
|
||||||
|
|
||||||
### `account`
|
|
||||||
|
|
||||||
Save a GitHub account with username, email, classic token, and platform.
|
|
||||||
|
|
||||||
```
|
|
||||||
guh create account <username> <email> <classicToken> <platform>
|
|
||||||
```
|
|
||||||
|
|
||||||
Credentials are stored in the user config directory under `dev.pages.codedave.guh/accounts.json`. All four values are required and must be non-empty. `platform` is the Git provider domain (e.g. `github.com`).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## `diff`
|
## `diff`
|
||||||
|
|
||||||
Show working tree changes.
|
Show working tree changes.
|
||||||
@@ -136,17 +197,17 @@ guh link add <name> <url> # add (or replace) a remote
|
|||||||
guh link remove <name> # remove a remote
|
guh link remove <name> # remove a remote
|
||||||
```
|
```
|
||||||
|
|
||||||
### `add`
|
### `link add`
|
||||||
|
|
||||||
Set a remote URL. Removes any existing remote with the same name first, then adds it.
|
Set a remote URL. Removes any existing remote with the same name first, then adds it. Requires exactly 2 arguments: remote name and URL.
|
||||||
|
|
||||||
```
|
```
|
||||||
guh link add <name> <url>
|
guh link add <name> <url>
|
||||||
```
|
```
|
||||||
|
|
||||||
### `remove`
|
### `link remove`
|
||||||
|
|
||||||
Remove a remote by name.
|
Remove a remote by name. Requires exactly 1 argument: the remote name.
|
||||||
|
|
||||||
```
|
```
|
||||||
guh link remove <name>
|
guh link remove <name>
|
||||||
@@ -154,6 +215,29 @@ guh link remove <name>
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## `logs`
|
||||||
|
|
||||||
|
Show commit logs.
|
||||||
|
|
||||||
|
```
|
||||||
|
guh logs [commits]
|
||||||
|
```
|
||||||
|
|
||||||
|
**Arguments**
|
||||||
|
|
||||||
|
| # | Name | Required | Description |
|
||||||
|
|---|------|----------|-------------|
|
||||||
|
| 1 | commits | no | Number of commits to show (default: all commits) |
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```
|
||||||
|
guh logs # git log (full history)
|
||||||
|
guh logs 5 # git log -5 (last 5 commits)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## `pull`
|
## `pull`
|
||||||
|
|
||||||
Fetch and pull upstream changes.
|
Fetch and pull upstream changes.
|
||||||
@@ -168,29 +252,21 @@ Runs `git fetch` followed by `git pull`.
|
|||||||
|
|
||||||
## `push`
|
## `push`
|
||||||
|
|
||||||
Push local commits to a remote.
|
Push the current branch to a remote. Uses `-u` to set upstream tracking automatically.
|
||||||
|
|
||||||
```
|
```
|
||||||
guh push # push to default remote
|
guh push # git push -u origin <current-branch>
|
||||||
guh push <remote> # push to a named remote
|
guh push <remote> # git push -u <remote> <current-branch>
|
||||||
guh push all # push to all remotes
|
guh push all # push to all remotes
|
||||||
```
|
```
|
||||||
|
|
||||||
When `all` is given, pushes to every remote returned by `git remote`.
|
When `all` is given, pushes to every remote returned by `git remote`. The first remote uses `-u` and the current branch name to set upstream tracking; subsequent remotes are pushed without the `-u` flag.
|
||||||
|
|
||||||
---
|
**Arguments**
|
||||||
|
|
||||||
## `rename`
|
| # | Name | Required | Description |
|
||||||
|
|---|------|----------|-------------|
|
||||||
### `branch`
|
| 1 | remote | no | Remote name, or `"all"` to push to every remote (default: `"origin"`) |
|
||||||
|
|
||||||
Rename the current branch.
|
|
||||||
|
|
||||||
```
|
|
||||||
guh rename branch <name>
|
|
||||||
```
|
|
||||||
|
|
||||||
Equivalent to `git branch -m <name>`.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -206,34 +282,9 @@ Equivalent to `git stash`.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## `switch`
|
|
||||||
|
|
||||||
### `branch`
|
|
||||||
|
|
||||||
Switch to an existing branch.
|
|
||||||
|
|
||||||
```
|
|
||||||
guh switch branch <name>
|
|
||||||
guh switch branch list
|
|
||||||
```
|
|
||||||
|
|
||||||
Equivalent to `git switch <name>`. Listing all branches is equivalent to `git branch`.
|
|
||||||
|
|
||||||
### `account`
|
|
||||||
|
|
||||||
Switch to a saved GitHub account (updates global git config and credentials).
|
|
||||||
|
|
||||||
```
|
|
||||||
guh switch account <username>
|
|
||||||
```
|
|
||||||
|
|
||||||
Sets `credential.helper` to `store`, updates `user.name` and `user.email` in global git config, and overwrites `~/.git-credentials` with the stored token. The account must have been created with `guh create account` first.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## `undo`
|
## `undo`
|
||||||
|
|
||||||
Undo local commits using `git reset`.
|
Undo local commits using `git reset`. Flavour defaults to `soft` for unrecognized values.
|
||||||
|
|
||||||
```
|
```
|
||||||
guh undo <commits> [flavour]
|
guh undo <commits> [flavour]
|
||||||
@@ -253,23 +304,3 @@ guh undo 1 # git reset --soft HEAD~1
|
|||||||
guh undo 2 hard # git reset --hard HEAD~2
|
guh undo 2 hard # git reset --hard HEAD~2
|
||||||
guh undo 1 mixed # git reset --mixed HEAD~1
|
guh undo 1 mixed # git reset --mixed HEAD~1
|
||||||
```
|
```
|
||||||
|
|
||||||
## `logs`
|
|
||||||
Show commit logs.
|
|
||||||
|
|
||||||
```
|
|
||||||
guh logs [commits]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Arguments**
|
|
||||||
|
|
||||||
| # | Name | Required | Description |
|
|
||||||
|---|------|----------|-------------|
|
|
||||||
| 1 | commits | no | Number of commits to show (default: all) |
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
```
|
|
||||||
guh logs 5
|
|
||||||
```
|
|
||||||
|
|
||||||
Equivalent to `git log`.
|
|
||||||
@@ -2,10 +2,18 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/daveberrys/guh/src/cmd"
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
_ "github.com/daveberrys/guh/src/cmd/create"
|
_ "github.com/daveberrys/guh/src/cmd/account"
|
||||||
_ "github.com/daveberrys/guh/src/cmd/switch"
|
_ "github.com/daveberrys/guh/src/cmd/branch"
|
||||||
_ "github.com/daveberrys/guh/src/cmd/browse"
|
_ "github.com/daveberrys/guh/src/cmd/browse"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/commit"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/diff"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/init"
|
||||||
_ "github.com/daveberrys/guh/src/cmd/link"
|
_ "github.com/daveberrys/guh/src/cmd/link"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/logs"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/pull"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/push"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/stash"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/undo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() { cmd.Execute() }
|
func main() { cmd.Execute() }
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cmd.RootCmd.AddCommand(accountCmd)
|
||||||
|
accountCmd.AddCommand(saveCmd)
|
||||||
|
accountCmd.AddCommand(switchCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var accountCmd = &cobra.Command{
|
||||||
|
Use: "account",
|
||||||
|
Short: "Manage accounts",
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package createcmd
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -8,9 +8,9 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var createAccountCmd = &cobra.Command{
|
var saveCmd = &cobra.Command{
|
||||||
Use: "account [username] [email] [classicToken] [platform]",
|
Use: "save [username] [email] [classicToken] [platform]",
|
||||||
Short: "Create or update an account",
|
Short: "Save a new account",
|
||||||
Args: cobra.ExactArgs(4),
|
Args: cobra.ExactArgs(4),
|
||||||
RunE: func(c *cobra.Command, args []string) error {
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
account := utils.Account{
|
account := utils.Account{
|
||||||
@@ -23,7 +23,9 @@ var createAccountCmd = &cobra.Command{
|
|||||||
return fmt.Errorf("username, email, classicToken, platform are required")
|
return fmt.Errorf("username, email, classicToken, platform are required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := utils.UpsertAccount(account); err != nil { return err }
|
if err := utils.UpsertAccount(account); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("Saved account: %s\n", account.Username)
|
fmt.Printf("Saved account: %s\n", account.Username)
|
||||||
return nil
|
return nil
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package switchcmd
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -9,27 +9,35 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var switchAccountCmd = &cobra.Command{
|
var switchCmd = &cobra.Command{
|
||||||
Use: "account [username]",
|
Use: "switch [username]",
|
||||||
Short: "Switch to a specific user account",
|
Short: "Switch to a saved account",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
RunE: func(c *cobra.Command, args []string) error {
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
account, err := utils.FindAccount(args[0])
|
account, err := utils.FindAccount(args[0])
|
||||||
if err != nil { return err }
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := utils.RunGitSequence(false,
|
if err := utils.RunGitSequence(false,
|
||||||
[]string{"config", "--global", "credential.helper", "store"},
|
[]string{"config", "--global", "credential.helper", "store"},
|
||||||
[]string{"config", "--global", "user.name", account.Username},
|
[]string{"config", "--global", "user.name", account.Username},
|
||||||
[]string{"config", "--global", "user.email", account.Email},
|
[]string{"config", "--global", "user.email", account.Email},
|
||||||
); err != nil { return err }
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err := os.UserHomeDir()
|
||||||
if err != nil { return err }
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
credentials := fmt.Sprintf("https://%s:%s@%s\n", account.Username, account.ClassicToken, account.Platform)
|
credentials := fmt.Sprintf("https://%s:%s@%s\n", account.Username, account.ClassicToken, account.Platform)
|
||||||
if err := os.WriteFile(filepath.Join(homeDir, ".git-credentials"), []byte(credentials), 0600); err != nil { return err }
|
if err := os.WriteFile(filepath.Join(homeDir, ".git-credentials"), []byte(credentials), 0600); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("Switched to account: %s\n", account.Username)
|
fmt.Printf("Switched to account: %s\n", account.Username)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package createcmd
|
package branch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var createBranchCmd = &cobra.Command{
|
var createCmd = &cobra.Command{
|
||||||
Use: "branch [branch]",
|
Use: "create [name]",
|
||||||
Short: "Create and switch to a branch",
|
Short: "Create and switch to a new branch",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
RunE: func(c *cobra.Command, args []string) error {
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
utils.RunGitSequence(false, []string{"switch", "-c", args[0]})
|
utils.RunGitSequence(false, []string{"switch", "-c", args[0]})
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package branch
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/daveberrys/guh/src/utils"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var renameCmd = &cobra.Command{
|
||||||
|
Use: "rename [name]",
|
||||||
|
Short: "Rename the current branch",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
utils.RunGitSequence(false, []string{"branch", "-m", args[0]})
|
||||||
|
fmt.Println("Successfully renamed branch to", args[0])
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package branch
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cmd.RootCmd.AddCommand(branchCmd)
|
||||||
|
branchCmd.AddCommand(createCmd)
|
||||||
|
branchCmd.AddCommand(switchCmd)
|
||||||
|
branchCmd.AddCommand(renameCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var branchCmd = &cobra.Command{
|
||||||
|
Use: "branch",
|
||||||
|
Short: "Manage branches",
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package switchcmd
|
package branch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -7,18 +7,17 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var switchBranchCmd = &cobra.Command{
|
var switchCmd = &cobra.Command{
|
||||||
Use: "branch [name]",
|
Use: "switch [name]",
|
||||||
Short: "Switch to a specific branch",
|
Short: "Switch to a branch, or list branches with 'list'",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
RunE: func(c *cobra.Command, args []string) error {
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
if args[0] == "list" {
|
if args[0] == "list" {
|
||||||
utils.RunGit(false, "branch")
|
utils.RunGit(false, "branch")
|
||||||
} else {
|
} else {
|
||||||
utils.RunGitSequence(false, []string{"switch", args[0]})
|
utils.RunGitSequence(false, []string{"switch", args[0]})
|
||||||
fmt.Printf("Switched to branch: %s\n", args[0])
|
fmt.Printf("Switched to branch: %s\n", args[0])
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,22 @@
|
|||||||
package cmd
|
package commit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { rootCmd.AddCommand(commitCmd) }
|
func init() { cmd.RootCmd.AddCommand(commitCmd) }
|
||||||
|
|
||||||
var commitCmd = &cobra.Command{
|
var commitCmd = &cobra.Command{
|
||||||
Use: "commit [files] [message] [description]",
|
Use: "commit [files] [message] [description]",
|
||||||
Short: "Add specified files and commit",
|
Short: "Add specified files and commit",
|
||||||
Args: cobra.RangeArgs(0, 5),
|
Args: cobra.RangeArgs(0, 5),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cobraCmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return utils.RunGitSequence(false, []string{"status", "--short"})
|
return utils.RunGitSequence(false, []string{"status", "--short"})
|
||||||
}
|
}
|
||||||
@@ -46,13 +47,8 @@ var commitCmd = &cobra.Command{
|
|||||||
commitArgs := []string{"commit", "-m", args[1]}
|
commitArgs := []string{"commit", "-m", args[1]}
|
||||||
afterPush, remoteName := false, "origin"
|
afterPush, remoteName := false, "origin"
|
||||||
|
|
||||||
// case 1 -> guh commit [files] [message] [desc] push[:optional] [remote_name:optional(origin)]
|
|
||||||
// case 2 -> guh commit [files] [message] push[:optional] [remote_name:optional(origin)]
|
|
||||||
// case 3 -> guh commit [files] [message] [desc]
|
|
||||||
// case 4 -> guh commit [files] [message]
|
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
case 5:
|
case 5:
|
||||||
// [files] [message] [desc] push [remote] (case 1)
|
|
||||||
commitArgs = append(commitArgs, "-m", args[2])
|
commitArgs = append(commitArgs, "-m", args[2])
|
||||||
afterPush = true
|
afterPush = true
|
||||||
if args[4] != "" {
|
if args[4] != "" {
|
||||||
@@ -60,22 +56,18 @@ var commitCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
case 4:
|
case 4:
|
||||||
if args[2] == "push" {
|
if args[2] == "push" {
|
||||||
// [files] [message] push [remote] (case 2)
|
|
||||||
afterPush = true
|
afterPush = true
|
||||||
if args[3] != "" {
|
if args[3] != "" {
|
||||||
remoteName = args[3]
|
remoteName = args[3]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// [files] [message] [desc] push (case 1)
|
|
||||||
commitArgs = append(commitArgs, "-m", args[2])
|
commitArgs = append(commitArgs, "-m", args[2])
|
||||||
afterPush = true
|
afterPush = true
|
||||||
}
|
}
|
||||||
case 3:
|
case 3:
|
||||||
if args[2] == "push" {
|
if args[2] == "push" {
|
||||||
// [files] [message] push (case 2)
|
|
||||||
afterPush = true
|
afterPush = true
|
||||||
} else {
|
} else {
|
||||||
// [files] [message] [desc] (case 3)
|
|
||||||
commitArgs = append(commitArgs, "-m", args[2])
|
commitArgs = append(commitArgs, "-m", args[2])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package createcmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/daveberrys/guh/src/cmd"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
cmd.RootCmd.AddCommand(createCmd)
|
|
||||||
createCmd.AddCommand(createBranchCmd)
|
|
||||||
createCmd.AddCommand(createAccountCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
var createCmd = &cobra.Command{
|
|
||||||
Use: "create",
|
|
||||||
Short: "Create branches or accounts",
|
|
||||||
}
|
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
package cmd
|
package diff
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { rootCmd.AddCommand(diffCmd) }
|
func init() { cmd.RootCmd.AddCommand(diffCmd) }
|
||||||
|
|
||||||
var diffCmd = &cobra.Command{
|
var diffCmd = &cobra.Command{
|
||||||
Use: "diff [file:optional]",
|
Use: "diff [file:optional]",
|
||||||
Short: "Show working tree changes",
|
Short: "Show working tree changes",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cobraCmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 1 { return utils.RunGitSequence(false, []string{"diff", args[0]}) }
|
if len(args) == 1 {
|
||||||
|
return utils.RunGitSequence(false, []string{"diff", args[0]})
|
||||||
|
}
|
||||||
return utils.RunGitSequence(false, []string{"diff"})
|
return utils.RunGitSequence(false, []string{"diff"})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
package cmd
|
package initcmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { rootCmd.AddCommand(initCmd) }
|
func init() { cmd.RootCmd.AddCommand(initCmd) }
|
||||||
|
|
||||||
var initCmd = &cobra.Command{
|
var initCmd = &cobra.Command{
|
||||||
Use: "init",
|
Use: "init",
|
||||||
Short: "Initialize a new repository",
|
Short: "Initialize a new repository",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cobraCmd *cobra.Command, args []string) error {
|
||||||
return utils.RunGitSequence(false, []string{"init"})
|
return utils.RunGitSequence(false, []string{"init"})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/daveberrys/guh/src/utils"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() { rootCmd.AddCommand(logCmd) }
|
|
||||||
|
|
||||||
var logCmd = &cobra.Command{
|
|
||||||
Use: "logs [commits]",
|
|
||||||
Short: "Show commits logs.",
|
|
||||||
Args: cobra.MaximumNArgs(1),
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
if len(args) == 0 {
|
|
||||||
return utils.RunGitSequence(false, []string{"log"})
|
|
||||||
}
|
|
||||||
return utils.RunGitSequence(false, []string{"log", "-"+args[0]})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package logs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
|
"github.com/daveberrys/guh/src/utils"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() { cmd.RootCmd.AddCommand(logCmd) }
|
||||||
|
|
||||||
|
var logCmd = &cobra.Command{
|
||||||
|
Use: "logs [commits]",
|
||||||
|
Short: "Show commits logs.",
|
||||||
|
Args: cobra.MaximumNArgs(1),
|
||||||
|
RunE: func(cobraCmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return utils.RunGitSequence(false, []string{"log"})
|
||||||
|
}
|
||||||
|
return utils.RunGitSequence(false, []string{"log", "-" + args[0]})
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
package cmd
|
package pull
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { rootCmd.AddCommand(pullCmd) }
|
func init() { cmd.RootCmd.AddCommand(pullCmd) }
|
||||||
|
|
||||||
var pullCmd = &cobra.Command{
|
var pullCmd = &cobra.Command{
|
||||||
Use: "pull",
|
Use: "pull",
|
||||||
Short: "Fetch and pull updates",
|
Short: "Fetch and pull updates",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cobraCmd *cobra.Command, args []string) error {
|
||||||
return utils.RunGitSequence(false,
|
return utils.RunGitSequence(false,
|
||||||
[]string{"fetch"},
|
[]string{"fetch"},
|
||||||
[]string{"pull"},
|
[]string{"pull"},
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
package cmd
|
package push
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { rootCmd.AddCommand(pushCmd) }
|
func init() { cmd.RootCmd.AddCommand(pushCmd) }
|
||||||
|
|
||||||
var pushCmd = &cobra.Command{
|
var pushCmd = &cobra.Command{
|
||||||
Use: "push [remote]",
|
Use: "push [remote]",
|
||||||
Short: "Add current changes and push",
|
Short: "Add current changes and push",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cobraCmd *cobra.Command, args []string) error {
|
||||||
branch, _ := utils.RunGit(true, "rev-parse", "--abbrev-ref", "HEAD")
|
branch, _ := utils.RunGit(true, "rev-parse", "--abbrev-ref", "HEAD")
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/daveberrys/guh/src/utils"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rootCmd.AddCommand(renameCmd)
|
|
||||||
renameCmd.AddCommand(renameBranchCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
var renameCmd = &cobra.Command{
|
|
||||||
Use: "rename",
|
|
||||||
Short: "Rename branches",
|
|
||||||
}
|
|
||||||
|
|
||||||
var renameBranchCmd = &cobra.Command{
|
|
||||||
Use: "branch [name]",
|
|
||||||
Short: "Rename a specific branch",
|
|
||||||
Args: cobra.ExactArgs(1),
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
return renameBranch(args[0])
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func renameBranch(branchName string) error {
|
|
||||||
utils.RunGitSequence(false, []string{"branch", "-m", branchName})
|
|
||||||
fmt.Println("Successfully renamed branch to", branchName)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
package cmd
|
package stash
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { rootCmd.AddCommand(stashCmd) }
|
func init() { cmd.RootCmd.AddCommand(stashCmd) }
|
||||||
|
|
||||||
var stashCmd = &cobra.Command{
|
var stashCmd = &cobra.Command{
|
||||||
Use: "stash",
|
Use: "stash",
|
||||||
Short: "Stash current changes",
|
Short: "Stash current changes",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cobraCmd *cobra.Command, args []string) error {
|
||||||
return utils.RunGitSequence(false, []string{"stash"})
|
return utils.RunGitSequence(false, []string{"stash"})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package switchcmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/daveberrys/guh/src/cmd"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
cmd.RootCmd.AddCommand(switchCmd)
|
|
||||||
switchCmd.AddCommand(switchBranchCmd)
|
|
||||||
switchCmd.AddCommand(switchAccountCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
var switchCmd = &cobra.Command{
|
|
||||||
Use: "switch",
|
|
||||||
Short: "Switch branches or accounts",
|
|
||||||
}
|
|
||||||
@@ -1,24 +1,26 @@
|
|||||||
package cmd
|
package undo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { RootCmd.AddCommand(undoCmd) }
|
func init() { cmd.RootCmd.AddCommand(undoCmd) }
|
||||||
|
|
||||||
var undoCmd = &cobra.Command{
|
var undoCmd = &cobra.Command{
|
||||||
Use: "undo [commits] [flavour]",
|
Use: "undo [commits] [flavour]",
|
||||||
Short: "Undo the last LOCAL commit. Flavour can be hard, mixed, or soft. It's optional.",
|
Short: "Undo the last LOCAL commit. Flavour can be hard, mixed, or soft. It's optional.",
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
RunE: func(c *cobra.Command, args []string) error {
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
var flavour string
|
var flavour string
|
||||||
switch args[1] {
|
switch args[1] {
|
||||||
case "hard":
|
case "hard":
|
||||||
flavour = "--hard"
|
flavour = "--hard"
|
||||||
case "mixed":
|
case "mixed":
|
||||||
flavour = "--mixed"
|
flavour = "--mixed"
|
||||||
default:
|
default:
|
||||||
flavour = "--soft"
|
flavour = "--soft"
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.RunGitSequence(false, []string{"reset", flavour, "HEAD~" + args[0]})
|
utils.RunGitSequence(false, []string{"reset", flavour, "HEAD~" + args[0]})
|
||||||
Reference in new issue
Block a user