mirror of
https://github.com/daveberrys/guh.git
synced 2026-11-29 00:46:45 +08:00
switch accounts, pull, push.
This commit is contained in:
1 parent
2b5c0dddc4
commit
3e87fa0d53
4 files changed
+51
-10
No files matched your search
+11
-5
@@ -2,6 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -15,10 +17,14 @@ var pullCmd = &cobra.Command{
|
|||||||
Short: "Pull updates from a source",
|
Short: "Pull updates from a source",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
source := "default"
|
|
||||||
if len(args) > 0 {
|
out, err := exec.Command("git", "fetch").CombinedOutput()
|
||||||
source = args[0]
|
if err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err) }
|
||||||
}
|
|
||||||
fmt.Printf("Pulling data from: %s...\n", source)
|
out, err = exec.Command("git", "pull").CombinedOutput()
|
||||||
|
if err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err) }
|
||||||
|
|
||||||
|
fmt.Print(string(out))
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
+8
-4
@@ -2,6 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -15,10 +17,12 @@ var pushCmd = &cobra.Command{
|
|||||||
Short: "Push changes to a destination",
|
Short: "Push changes to a destination",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
dest := "origin"
|
dest := "main"
|
||||||
if len(args) > 0 {
|
if len(args) > 0 { dest = args[0] }
|
||||||
dest = args[0]
|
|
||||||
}
|
|
||||||
fmt.Printf("Pushing changes to: %s...\n", dest)
|
fmt.Printf("Pushing changes to: %s...\n", dest)
|
||||||
|
|
||||||
|
out, err := exec.Command("git", "push", "origin", dest).CombinedOutput()
|
||||||
|
if err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err) }
|
||||||
|
fmt.Print(string(out))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// COMMAND LINE INTERFACE GOES HERE
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(saveCmd)
|
||||||
|
saveCmd.AddCommand(accountSaveCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var saveCmd = &cobra.Command{
|
||||||
|
Use: "save",
|
||||||
|
Short: "Save accounts,",
|
||||||
|
}
|
||||||
|
|
||||||
|
var accountSaveCmd = &cobra.Command{
|
||||||
|
Use: "account [username]",
|
||||||
|
Short: "Save a specific user account",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
performAccountSave(args[0])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// PERFORMERS GO HERE
|
||||||
|
func performAccountSave(username string) {
|
||||||
|
fmt.Printf("Saved account: %s\n", username)
|
||||||
|
}
|
||||||
+1
-1
@@ -14,7 +14,7 @@ func init() {
|
|||||||
|
|
||||||
var switchCmd = &cobra.Command{
|
var switchCmd = &cobra.Command{
|
||||||
Use: "switch",
|
Use: "switch",
|
||||||
Short: "Switch context, branches, or accounts",
|
Short: "Switch branches or accounts",
|
||||||
}
|
}
|
||||||
|
|
||||||
var switchBranchCmd = &cobra.Command{
|
var switchBranchCmd = &cobra.Command{
|
||||||
|
|||||||
Reference in new issue
Block a user