Skip to content

Commit

Permalink
Transitional commit
Browse files Browse the repository at this point in the history
  • Loading branch information
telemachus committed Oct 24, 2024
1 parent dd1992d commit ead25cb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ testr:
go test -race -shuffle on github.com/telemachus/gitmirror/cli

build: lint testr
go build -o gitmirror ./cmd/gitmirror/main.go
go build -o gitmirror-init ./cmd/gitmirror-init/main.go
go build -o gitmirror-update ./cmd/gitmirror-update/main.go

install: build
mv gitmirror $(HOME)/bin/gitmirror
mv gitmirror-init $(HOME)/bin/gitmirror-init
mv gitmirror-update $(HOME)/bin/gitmirror-update

clean:
go clean -i -r -cache
rm gitmirror
rm gitmirror-init
rm gitmirror-update

Expand Down
61 changes: 61 additions & 0 deletions cli/wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cli

import (
"fmt"
"os"
"os/exec"
"syscall"
)

const (
wrapperCmd = "gitmirror"
wrapperVersion = "0.1.0"
wrapperUsage = `usage: gitmirror <command> [options]
The commands are:
initialize|init
update|up
version
Use "gitmirror help <command>" for more information about a command.
`
)

// CmdWrapper turns, e.g., `gitmirror update --q` into `gitmirror-update --q`.
func CmdWrapper(args []string) int {
if len(args) < 1 {
fmt.Fprint(os.Stderr, wrapperUsage)
return exitFailure
}
switch args[0] {
case "initialize", "init":
binary, lookErr := exec.LookPath("gitmirror-init")
if lookErr != nil {
fmt.Fprintf(os.Stdout, "%s: v%s\n", wrapperCmd, lookErr)
return exitFailure
}
cmdArgs := make([]string, 0, len(args))
cmdArgs = append(cmdArgs, "gitmirror-init")
cmdArgs = append(cmdArgs, args[1:]...)
env := os.Environ()
execErr := syscall.Exec(binary, cmdArgs, env)
if execErr != nil {
fmt.Fprintf(os.Stdout, "%s: v%s\n", wrapperCmd, execErr)
return exitFailure
}
case "update", "up":
cmdArgs := args[1:]
cmd := exec.Command("gitmirror-update", cmdArgs...)
err := cmd.Run()
if err != nil {
fmt.Fprintf(os.Stdout, "%s: v%s\n", wrapperCmd, err)
return exitFailure
}
case "version":
fmt.Fprintf(os.Stdout, "%s: v%s\n", wrapperCmd, wrapperVersion)
default:
fmt.Fprint(os.Stderr, wrapperUsage)
return exitFailure
}
return exitSuccess
}

0 comments on commit ead25cb

Please sign in to comment.