Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Improved style
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasdille committed Jun 13, 2023
1 parent 8634f18 commit 6348459
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 314 deletions.
2 changes: 1 addition & 1 deletion cmd/docker-setup/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var describeCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("error getting tool %s", args[0])
}
tool.ReplaceVariables(prefix+target, arch, alt_arch)
tool.ReplaceVariables(prefix+target, arch, altArch)

if describeOutput == "pretty" {
tool.Print()
Expand Down
32 changes: 0 additions & 32 deletions cmd/docker-setup/dev.go

This file was deleted.

8 changes: 4 additions & 4 deletions cmd/docker-setup/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/nicholasdille/docker-setup/pkg/tool"
)

var alt_arch string = runtime.GOARCH
var altArch string = runtime.GOARCH
var arch string

var prefix = ""
Expand All @@ -29,7 +29,7 @@ var toolSeparator = "/"
var registryImagePrefix = registry + "/" + repository + toolSeparator
var tools tool.Tools

var emoji_tool = "\U0001F528"
var emojiTool = "\U0001F528"

func directoryExists(directory string) bool {
log.Tracef("Checking if directory %s exists", directory)
Expand Down Expand Up @@ -116,10 +116,10 @@ func assertMetadataIsLoaded() {
}

func initDockerSetup() {
if alt_arch == "amd64" {
if altArch == "amd64" {
arch = "x86_64"

} else if alt_arch == "arm64" {
} else if altArch == "arm64" {
arch = "aarch64"

} else {
Expand Down
6 changes: 3 additions & 3 deletions cmd/docker-setup/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ var inspectCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("error getting tool %s", args[0])
}
tool.ReplaceVariables(prefix+target, arch, alt_arch)
tool.ReplaceVariables(prefix+target, arch, altArch)

fmt.Printf("%s Inspecting %s %s\n", emoji_tool, tool.Name, tool.Version)
err = tool.Inspect(registryImagePrefix, alt_arch)
fmt.Printf("%s Inspecting %s %s\n", emojiTool, tool.Name, tool.Version)
err = tool.Inspect(registryImagePrefix, altArch)
if err != nil {
return fmt.Errorf("unable to inspect %s: %s", tool.Name, err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/docker-setup/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var installCmd = &cobra.Command{
log.Debugf("Collecting installed tools")
for index, tool := range tools.Tools {
log.Tracef("Getting status for requested tool %s", tool.Name)
tools.Tools[index].ReplaceVariables(prefix+"/"+target, arch, alt_arch)
tools.Tools[index].ReplaceVariables(prefix+"/"+target, arch, altArch)

err := tools.Tools[index].GetBinaryStatus()
if err != nil {
Expand Down Expand Up @@ -107,7 +107,7 @@ var installCmd = &cobra.Command{
// TODO: Display spinner
for index, tool := range plannedTools.Tools {
log.Tracef("Getting status for requested tool %s", tool.Name)
plannedTools.Tools[index].ReplaceVariables(prefix+"/"+target, arch, alt_arch)
plannedTools.Tools[index].ReplaceVariables(prefix+"/"+target, arch, altArch)

err := plannedTools.Tools[index].GetBinaryStatus()
if err != nil {
Expand Down Expand Up @@ -155,8 +155,8 @@ var installCmd = &cobra.Command{
continue
}

fmt.Printf("%s Installing %s %s", emoji_tool, tool.Name, tool.Version)
err := tool.Install(registryImagePrefix, prefix+"/", alt_arch)
fmt.Printf("%s Installing %s %s", emojiTool, tool.Name, tool.Version)
err := tool.Install(registryImagePrefix, prefix+"/", altArch)
fmt.Printf("\n")
if err != nil {
return fmt.Errorf("unable to install %s: %s", tool.Name, err)
Expand Down Expand Up @@ -188,7 +188,7 @@ var installCmd = &cobra.Command{
"prefix="+prefix,
"target="+target,
"arch="+arch,
"alt_arch="+alt_arch,
"altArch="+altArch,
)
output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
17 changes: 0 additions & 17 deletions cmd/docker-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

git "github.com/go-git/go-git/v5"
)

var version string = "main"
Expand Down Expand Up @@ -46,21 +44,6 @@ func init() {
initUninstallCmd()
initUpdateCmd()
initVersionCmd()

if fileExists(".git/config") {
repo, err := git.PlainOpen(".")
if err != nil {
log.Fatal(err)
}
config, err := repo.Config()
if err != nil {
log.Fatal(err)
}
origin := config.Remotes["origin"]
if origin.URLs[0] == "https://github.com/nicholasdille/docker-setup" {
initDevCmd()
}
}
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/docker-setup/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var updateCmd = &cobra.Command{
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
assertCacheDirectory()
containers.GetManifest(registryImagePrefix+"metadata:main", alt_arch, func(blob blob.Reader) error {
containers.GetManifest(registryImagePrefix+"metadata:main", altArch, func(blob blob.Reader) error {
err := os.Chdir(prefix + "/" + cacheDirectory)
if err != nil {
fmt.Printf("Error changing directory to %s: %s\n", prefix+"/"+cacheDirectory, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/docker-setup/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var versionCmd = &cobra.Command{
Short: "Show version",
Long: header + "\nShow version",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("docker-setup version %s\n", version)
},
}
21 changes: 2 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/nicholasdille/docker-setup
go 1.20

require (
github.com/go-git/go-git/v5 v5.7.0
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/opencontainers/go-digest v1.0.0
github.com/regclient/regclient v0.4.8
Expand All @@ -14,29 +13,13 @@ require (
)

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.2.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
Loading

0 comments on commit 6348459

Please sign in to comment.