diff --git a/DOCS.md b/DOCS.md index 1ae1bd8..61a4c91 100644 --- a/DOCS.md +++ b/DOCS.md @@ -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 +``` + +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 +``` + +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 +``` + +Equivalent to `git switch -c `. + +### `branch switch` + +Switch to an existing branch, or list branches. + +``` +guh branch switch +guh branch switch list +``` + +Equivalent to `git switch `. Using `list` is equivalent to `git branch`. + +### `branch rename` + +Rename the current branch. + +``` +guh branch rename +``` + +Equivalent to `git branch -m `. + +--- + ## `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 -``` - -Equivalent to `git switch -c `. - -### `account` - -Save a GitHub account with username, email, classic token, and platform. - -``` -guh create account -``` - -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 # add (or replace) a remote guh link remove # 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 ``` -### `remove` +### `link remove` -Remove a remote by name. +Remove a remote by name. Requires exactly 1 argument: the remote name. ``` guh link remove @@ -154,6 +215,29 @@ guh link remove --- +## `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 # push to a named remote +guh push # git push -u origin +guh push # git push -u 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 -``` - -Equivalent to `git branch -m `. +| # | 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 -guh switch branch list -``` - -Equivalent to `git switch `. Listing all branches is equivalent to `git branch`. - -### `account` - -Switch to a saved GitHub account (updates global git config and credentials). - -``` -guh switch account -``` - -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 [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`. diff --git a/main.go b/main.go index 155a334..84107e7 100644 --- a/main.go +++ b/main.go @@ -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() } diff --git a/src/cmd/account/root.go b/src/cmd/account/root.go new file mode 100644 index 0000000..1d62d41 --- /dev/null +++ b/src/cmd/account/root.go @@ -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", +} diff --git a/src/cmd/create/account.go b/src/cmd/account/save.go similarity index 74% rename from src/cmd/create/account.go rename to src/cmd/account/save.go index 10ffcf6..c7fcdc0 100644 --- a/src/cmd/create/account.go +++ b/src/cmd/account/save.go @@ -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 diff --git a/src/cmd/switch/account.go b/src/cmd/account/switch.go similarity index 65% rename from src/cmd/switch/account.go rename to src/cmd/account/switch.go index ef336f6..f13f51d 100644 --- a/src/cmd/switch/account.go +++ b/src/cmd/account/switch.go @@ -1,4 +1,4 @@ -package switchcmd +package account import ( "fmt" @@ -9,27 +9,35 @@ 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", "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 }, -} \ No newline at end of file +} diff --git a/src/cmd/create/branch.go b/src/cmd/branch/create.go similarity index 67% rename from src/cmd/create/branch.go rename to src/cmd/branch/create.go index b7a2a07..b4e275a 100644 --- a/src/cmd/create/branch.go +++ b/src/cmd/branch/create.go @@ -1,15 +1,15 @@ -package createcmd +package branch import ( - "fmt" - + "fmt" + "github.com/daveberrys/guh/src/utils" "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]}) diff --git a/src/cmd/branch/rename.go b/src/cmd/branch/rename.go new file mode 100644 index 0000000..41a053e --- /dev/null +++ b/src/cmd/branch/rename.go @@ -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 + }, +} diff --git a/src/cmd/branch/root.go b/src/cmd/branch/root.go new file mode 100644 index 0000000..0c58f18 --- /dev/null +++ b/src/cmd/branch/root.go @@ -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", +} diff --git a/src/cmd/switch/branch.go b/src/cmd/branch/switch.go similarity index 52% rename from src/cmd/switch/branch.go rename to src/cmd/branch/switch.go index a8d7a04..27159ae 100644 --- a/src/cmd/switch/branch.go +++ b/src/cmd/branch/switch.go @@ -1,4 +1,4 @@ -package switchcmd +package branch import ( "fmt" @@ -7,18 +7,17 @@ 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" { + if args[0] == "list" { utils.RunGit(false, "branch") - } else { + } else { 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 }, -} \ No newline at end of file +} diff --git a/src/cmd/commit.go b/src/cmd/commit/root.go similarity index 74% rename from src/cmd/commit.go rename to src/cmd/commit/root.go index e3c1d7d..a091454 100644 --- a/src/cmd/commit.go +++ b/src/cmd/commit/root.go @@ -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 { + Args: cobra.RangeArgs(0, 5), + 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]) } } diff --git a/src/cmd/create/root.go b/src/cmd/create/root.go deleted file mode 100644 index d26f98d..0000000 --- a/src/cmd/create/root.go +++ /dev/null @@ -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", -} diff --git a/src/cmd/diff.go b/src/cmd/diff/root.go similarity index 52% rename from src/cmd/diff.go rename to src/cmd/diff/root.go index 3079daf..6aa71b6 100644 --- a/src/cmd/diff.go +++ b/src/cmd/diff/root.go @@ -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"}) }, } diff --git a/src/cmd/init.go b/src/cmd/init/root.go similarity index 60% rename from src/cmd/init.go rename to src/cmd/init/root.go index fba9b3e..07b5a74 100644 --- a/src/cmd/init.go +++ b/src/cmd/init/root.go @@ -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"}) }, } diff --git a/src/cmd/logs.go b/src/cmd/logs.go deleted file mode 100644 index 371fa42..0000000 --- a/src/cmd/logs.go +++ /dev/null @@ -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]}) - }, -} diff --git a/src/cmd/logs/root.go b/src/cmd/logs/root.go new file mode 100644 index 0000000..b51fac9 --- /dev/null +++ b/src/cmd/logs/root.go @@ -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]}) + }, +} diff --git a/src/cmd/pull.go b/src/cmd/pull/root.go similarity index 63% rename from src/cmd/pull.go rename to src/cmd/pull/root.go index aeb9dce..63c8688 100644 --- a/src/cmd/pull.go +++ b/src/cmd/pull/root.go @@ -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"}, diff --git a/src/cmd/push.go b/src/cmd/push/root.go similarity index 83% rename from src/cmd/push.go rename to src/cmd/push/root.go index 8fa5435..3442026 100644 --- a/src/cmd/push.go +++ b/src/cmd/push/root.go @@ -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 { diff --git a/src/cmd/rename.go b/src/cmd/rename.go deleted file mode 100644 index a9234a9..0000000 --- a/src/cmd/rename.go +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/src/cmd/stash.go b/src/cmd/stash/root.go similarity index 60% rename from src/cmd/stash.go rename to src/cmd/stash/root.go index e319107..138fd58 100644 --- a/src/cmd/stash.go +++ b/src/cmd/stash/root.go @@ -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"}) }, } diff --git a/src/cmd/switch/root.go b/src/cmd/switch/root.go deleted file mode 100644 index e76b82a..0000000 --- a/src/cmd/switch/root.go +++ /dev/null @@ -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", -} \ No newline at end of file diff --git a/src/cmd/undo.go b/src/cmd/undo/root.go similarity index 64% rename from src/cmd/undo.go rename to src/cmd/undo/root.go index c7713df..448a13a 100644 --- a/src/cmd/undo.go +++ b/src/cmd/undo/root.go @@ -1,24 +1,26 @@ -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]", 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 { var flavour string switch args[1] { - case "hard": - flavour = "--hard" - case "mixed": - flavour = "--mixed" - default: - flavour = "--soft" + case "hard": + flavour = "--hard" + case "mixed": + flavour = "--mixed" + default: + flavour = "--soft" } utils.RunGitSequence(false, []string{"reset", flavour, "HEAD~" + args[0]})