mirror of
https://github.com/daveberrys/guh.git
synced 2026-11-29 00:46:45 +08:00
initialize file structure
This commit is contained in:
commit
2b5c0dddc4
8 files changed
+154
No files matched your search
@@ -0,0 +1,9 @@
|
|||||||
|
module github.com/daveberrys/guh
|
||||||
|
|
||||||
|
go 1.26.3
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
|
github.com/spf13/cobra v1.10.2 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.9 // indirect
|
||||||
|
)
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
||||||
|
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
|
||||||
|
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
|
||||||
|
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cmd.Execute()
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(pullCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var pullCmd = &cobra.Command{
|
||||||
|
Use: "pull [source]",
|
||||||
|
Short: "Pull updates from a source",
|
||||||
|
Args: cobra.MaximumNArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
source := "default"
|
||||||
|
if len(args) > 0 {
|
||||||
|
source = args[0]
|
||||||
|
}
|
||||||
|
fmt.Printf("Pulling data from: %s...\n", source)
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(pushCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var pushCmd = &cobra.Command{
|
||||||
|
Use: "push [destination]",
|
||||||
|
Short: "Push changes to a destination",
|
||||||
|
Args: cobra.MaximumNArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
dest := "origin"
|
||||||
|
if len(args) > 0 {
|
||||||
|
dest = args[0]
|
||||||
|
}
|
||||||
|
fmt.Printf("Pushing changes to: %s...\n", dest)
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "guh",
|
||||||
|
Short: "Guh is a modular CLI tool",
|
||||||
|
Long: `A comprehensive CLI tool built with Go and Cobra to demonstrate multi-command structures.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
// This runs if no subcommand is provided
|
||||||
|
fmt.Println("Welcome to guh! Use --help to see available commands.")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
|
func Execute() {
|
||||||
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// COMMAND LINE INTERFACE GOES HERE
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(switchCmd)
|
||||||
|
switchCmd.AddCommand(switchBranchCmd)
|
||||||
|
switchCmd.AddCommand(switchAccountCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var switchCmd = &cobra.Command{
|
||||||
|
Use: "switch",
|
||||||
|
Short: "Switch context, branches, or accounts",
|
||||||
|
}
|
||||||
|
|
||||||
|
var switchBranchCmd = &cobra.Command{
|
||||||
|
Use: "branch [name]",
|
||||||
|
Short: "Switch to a specific branch",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
performBranchSwitch(args[0])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var switchAccountCmd = &cobra.Command{
|
||||||
|
Use: "account [username]",
|
||||||
|
Short: "Switch to a specific user account",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
performAccountSwitch(args[0])
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// PERFORMERS GO HERE
|
||||||
|
func performAccountSwitch(username string) {
|
||||||
|
fmt.Printf("Switched to account: %s\n", username)
|
||||||
|
}
|
||||||
|
|
||||||
|
func performBranchSwitch(branchName string) {
|
||||||
|
fmt.Printf("Switched to branch: %s\n", branchName)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import ("fmt")
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
fmt.Println("json read, save, delete logic goes here")
|
||||||
|
}
|
||||||
Reference in new issue
Block a user