chore(go): scaffold module and add failing link tests
This commit is contained in:
113
internal/homesick/cli/cli.go
Normal file
113
internal/homesick/cli/cli.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"git.hrafn.xyz/aether/gosick/internal/homesick/core"
|
||||
"git.hrafn.xyz/aether/gosick/internal/homesick/version"
|
||||
)
|
||||
|
||||
func Run(args []string, stdout io.Writer, stderr io.Writer) int {
|
||||
app, err := core.New(stdout, stderr)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
printHelp(stdout)
|
||||
return 0
|
||||
}
|
||||
|
||||
command := args[0]
|
||||
switch command {
|
||||
case "-v", "--version", "version":
|
||||
if err := app.Version(version.String); err != nil {
|
||||
_, _ = fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
case "help", "--help", "-h":
|
||||
printHelp(stdout)
|
||||
return 0
|
||||
case "clone":
|
||||
if len(args) < 2 {
|
||||
_, _ = fmt.Fprintln(stderr, "error: clone requires URI")
|
||||
return 1
|
||||
}
|
||||
destination := ""
|
||||
if len(args) > 2 {
|
||||
destination = args[2]
|
||||
}
|
||||
if err := app.Clone(args[1], destination); err != nil {
|
||||
_, _ = fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
case "list":
|
||||
if err := app.List(); err != nil {
|
||||
_, _ = fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
case "show_path":
|
||||
castle := defaultCastle(args)
|
||||
if err := app.ShowPath(castle); err != nil {
|
||||
_, _ = fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
case "status":
|
||||
castle := defaultCastle(args)
|
||||
if err := app.Status(castle); err != nil {
|
||||
_, _ = fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
case "diff":
|
||||
castle := defaultCastle(args)
|
||||
if err := app.Diff(castle); err != nil {
|
||||
_, _ = fmt.Fprintf(stderr, "error: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
case "link", "unlink", "track", "pull", "push", "commit", "destroy", "cd", "open", "exec", "exec_all", "rc", "generate":
|
||||
_, _ = fmt.Fprintf(stderr, "error: %s is not implemented in Go yet\n", command)
|
||||
return 2
|
||||
default:
|
||||
_, _ = fmt.Fprintf(stderr, "error: unknown command %q\n\n", command)
|
||||
printHelp(stderr)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
func defaultCastle(args []string) string {
|
||||
if len(args) > 1 && strings.TrimSpace(args[1]) != "" {
|
||||
return args[1]
|
||||
}
|
||||
return "dotfiles"
|
||||
}
|
||||
|
||||
func printHelp(w io.Writer) {
|
||||
_, _ = fmt.Fprintln(w, "homesick (Go scaffold)")
|
||||
_, _ = fmt.Fprintln(w, "")
|
||||
_, _ = fmt.Fprintln(w, "Implemented commands:")
|
||||
_, _ = fmt.Fprintln(w, " clone URI [CASTLE_NAME]")
|
||||
_, _ = fmt.Fprintln(w, " list")
|
||||
_, _ = fmt.Fprintln(w, " show_path [CASTLE]")
|
||||
_, _ = fmt.Fprintln(w, " status [CASTLE]")
|
||||
_, _ = fmt.Fprintln(w, " diff [CASTLE]")
|
||||
_, _ = fmt.Fprintln(w, " version | -v | --version")
|
||||
_, _ = fmt.Fprintln(w, "")
|
||||
_, _ = fmt.Fprintln(w, "Not implemented yet:")
|
||||
_, _ = fmt.Fprintln(w, " link, unlink, track, pull, push, commit, destroy, cd, open, exec, exec_all, rc, generate")
|
||||
_, _ = fmt.Fprintln(w, "")
|
||||
_, _ = fmt.Fprintln(w, "Build: go build -o dist/homesick-go ./cmd/homesick")
|
||||
}
|
||||
|
||||
func init() {
|
||||
_ = os.Setenv("GIT_TERMINAL_PROMPT", "0")
|
||||
}
|
||||
Reference in New Issue
Block a user