organize file system, update docs

This commit is contained in:
daveberrys committed 2026-07-19 11:12:14 +08:00
1 parent 932823fdde
commit 7a71d0e89d
21 files changed
+272 -235

No files matched your search

+124 -93
View File
@@ -1,5 +1,32 @@
# 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`
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`
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.
### `issues`
### `browse issues`
Open the issues page.
@@ -29,7 +115,7 @@ Open the issues page.
guh browse issues
```
### `pr`
### `browse pr`
Open the pull requests page.
@@ -45,7 +131,6 @@ guh browse pr print
guh browse print
```
---
## `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`
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
```
### `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>
```
### `remove`
### `link remove`
Remove a remote by name.
Remove a remote by name. Requires exactly 1 argument: the remote 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`
Fetch and pull upstream changes.
@@ -168,29 +252,21 @@ Runs `git fetch` followed by `git pull`.
## `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 <remote> # push to a named remote
guh push # git push -u origin <current-branch>
guh push <remote> # git push -u <remote> <current-branch>
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`
### `branch`
Rename the current branch.
```
guh rename branch <name>
```
Equivalent to `git branch -m <name>`.
| # | Name | Required | Description |
|---|------|----------|-------------|
| 1 | remote | no | Remote name, or `"all"` to push to every remote (default: `"origin"`) |
---
@@ -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 local commits using `git reset`.
Undo local commits using `git reset`. Flavour defaults to `soft` for unrecognized values.
```
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 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`.
+10 -2
View File
@@ -2,10 +2,18 @@ package main
import (
"github.com/daveberrys/guh/src/cmd"
_ "github.com/daveberrys/guh/src/cmd/create"
_ "github.com/daveberrys/guh/src/cmd/switch"
_ "github.com/daveberrys/guh/src/cmd/account"
_ "github.com/daveberrys/guh/src/cmd/branch"
_ "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/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() }
+17
View File
@@ -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 (
"fmt"
@@ -8,9 +8,9 @@ import (
"github.com/spf13/cobra"
)
var createAccountCmd = &cobra.Command{
Use: "account [username] [email] [classicToken] [platform]",
Short: "Create or update an account",
var saveCmd = &cobra.Command{
Use: "save [username] [email] [classicToken] [platform]",
Short: "Save a new account",
Args: cobra.ExactArgs(4),
RunE: func(c *cobra.Command, args []string) error {
account := utils.Account{
@@ -23,7 +23,9 @@ var createAccountCmd = &cobra.Command{
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)
return nil
@@ -1,4 +1,4 @@
package switchcmd
package account
import (
"fmt"
@@ -9,25 +9,33 @@ import (
"github.com/spf13/cobra"
)
var switchAccountCmd = &cobra.Command{
Use: "account [username]",
Short: "Switch to a specific user account",
var switchCmd = &cobra.Command{
Use: "switch [username]",
Short: "Switch to a saved account",
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
account, err := utils.FindAccount(args[0])
if err != nil { return err }
if err != nil {
return err
}
if err := utils.RunGitSequence(false,
[]string{"config", "--global", "credential.helper", "store"},
[]string{"config", "--global", "user.name", account.Username},
[]string{"config", "--global", "user.email", account.Email},
); err != nil { return err }
); err != nil {
return err
}
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)
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)
return nil
@@ -1,4 +1,4 @@
package createcmd
package branch
import (
"fmt"
@@ -7,9 +7,9 @@ import (
"github.com/spf13/cobra"
)
var createBranchCmd = &cobra.Command{
Use: "branch [branch]",
Short: "Create and switch to a branch",
var createCmd = &cobra.Command{
Use: "create [name]",
Short: "Create and switch to a new branch",
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
utils.RunGitSequence(false, []string{"switch", "-c", args[0]})
+19
View File
@@ -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
},
}
+18
View File
@@ -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 (
"fmt"
@@ -7,9 +7,9 @@ import (
"github.com/spf13/cobra"
)
var switchBranchCmd = &cobra.Command{
Use: "branch [name]",
Short: "Switch to a specific branch",
var switchCmd = &cobra.Command{
Use: "switch [name]",
Short: "Switch to a branch, or list branches with 'list'",
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
if args[0] == "list" {
@@ -18,7 +18,6 @@ var switchBranchCmd = &cobra.Command{
utils.RunGitSequence(false, []string{"switch", args[0]})
fmt.Printf("Switched to branch: %s\n", args[0])
}
return nil
},
}
+4 -12
View File
@@ -1,21 +1,22 @@
package cmd
package commit
import (
"encoding/json"
"fmt"
"strings"
"github.com/daveberrys/guh/src/cmd"
"github.com/daveberrys/guh/src/utils"
"github.com/spf13/cobra"
)
func init() { rootCmd.AddCommand(commitCmd) }
func init() { cmd.RootCmd.AddCommand(commitCmd) }
var commitCmd = &cobra.Command{
Use: "commit [files] [message] [description]",
Short: "Add specified files and commit",
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 {
return utils.RunGitSequence(false, []string{"status", "--short"})
}
@@ -46,13 +47,8 @@ var commitCmd = &cobra.Command{
commitArgs := []string{"commit", "-m", args[1]}
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) {
case 5:
// [files] [message] [desc] push [remote] (case 1)
commitArgs = append(commitArgs, "-m", args[2])
afterPush = true
if args[4] != "" {
@@ -60,22 +56,18 @@ var commitCmd = &cobra.Command{
}
case 4:
if args[2] == "push" {
// [files] [message] push [remote] (case 2)
afterPush = true
if args[3] != "" {
remoteName = args[3]
}
} else {
// [files] [message] [desc] push (case 1)
commitArgs = append(commitArgs, "-m", args[2])
afterPush = true
}
case 3:
if args[2] == "push" {
// [files] [message] push (case 2)
afterPush = true
} else {
// [files] [message] [desc] (case 3)
commitArgs = append(commitArgs, "-m", args[2])
}
}
-17
View File
@@ -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",
}
+7 -4
View File
@@ -1,18 +1,21 @@
package cmd
package diff
import (
"github.com/daveberrys/guh/src/cmd"
"github.com/daveberrys/guh/src/utils"
"github.com/spf13/cobra"
)
func init() { rootCmd.AddCommand(diffCmd) }
func init() { cmd.RootCmd.AddCommand(diffCmd) }
var diffCmd = &cobra.Command{
Use: "diff [file:optional]",
Short: "Show working tree changes",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 { return utils.RunGitSequence(false, []string{"diff", args[0]}) }
RunE: func(cobraCmd *cobra.Command, args []string) error {
if len(args) == 1 {
return utils.RunGitSequence(false, []string{"diff", args[0]})
}
return utils.RunGitSequence(false, []string{"diff"})
},
}
+4 -3
View File
@@ -1,17 +1,18 @@
package cmd
package initcmd
import (
"github.com/daveberrys/guh/src/cmd"
"github.com/daveberrys/guh/src/utils"
"github.com/spf13/cobra"
)
func init() { rootCmd.AddCommand(initCmd) }
func init() { cmd.RootCmd.AddCommand(initCmd) }
var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize a new repository",
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"})
},
}
-20
View File
@@ -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]})
},
}
+21
View File
@@ -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]})
},
}
+4 -3
View File
@@ -1,17 +1,18 @@
package cmd
package pull
import (
"github.com/daveberrys/guh/src/cmd"
"github.com/daveberrys/guh/src/utils"
"github.com/spf13/cobra"
)
func init() { rootCmd.AddCommand(pullCmd) }
func init() { cmd.RootCmd.AddCommand(pullCmd) }
var pullCmd = &cobra.Command{
Use: "pull",
Short: "Fetch and pull updates",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cobraCmd *cobra.Command, args []string) error {
return utils.RunGitSequence(false,
[]string{"fetch"},
[]string{"pull"},
+4 -3
View File
@@ -1,19 +1,20 @@
package cmd
package push
import (
"strings"
"github.com/daveberrys/guh/src/cmd"
"github.com/daveberrys/guh/src/utils"
"github.com/spf13/cobra"
)
func init() { rootCmd.AddCommand(pushCmd) }
func init() { cmd.RootCmd.AddCommand(pushCmd) }
var pushCmd = &cobra.Command{
Use: "push [remote]",
Short: "Add current changes and push",
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")
if len(args) == 0 {
-33
View File
@@ -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
}
+4 -3
View File
@@ -1,17 +1,18 @@
package cmd
package stash
import (
"github.com/daveberrys/guh/src/cmd"
"github.com/daveberrys/guh/src/utils"
"github.com/spf13/cobra"
)
func init() { rootCmd.AddCommand(stashCmd) }
func init() { cmd.RootCmd.AddCommand(stashCmd) }
var stashCmd = &cobra.Command{
Use: "stash",
Short: "Stash current changes",
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"})
},
}
-17
View File
@@ -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",
}
+5 -3
View File
@@ -1,10 +1,12 @@
package cmd
package undo
import (
"github.com/spf13/cobra"
"github.com/daveberrys/guh/src/cmd"
"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{
Use: "undo [commits] [flavour]",