Skip to content

Commit

Permalink
Fixes after linting
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasdille committed Oct 12, 2023
1 parent 347c524 commit b12322d
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 28 deletions.
15 changes: 12 additions & 3 deletions cmd/uniget/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ var describeCmd = &cobra.Command{
return fmt.Errorf("error getting tool %s", toolName)
}
tool.ReplaceVariables(prefix+"/"+target, arch, altArch)
tool.GetMarkerFileStatus(prefix + "/" + cacheDirectory)
tool.GetBinaryStatus()
tool.GetVersionStatus()
err = tool.GetMarkerFileStatus(prefix + "/" + cacheDirectory)
if err != nil {
return fmt.Errorf("error getting marker file status: %s", err)
}
err = tool.GetBinaryStatus()
if err != nil {
return fmt.Errorf("error getting binary status: %s", err)
}
err = tool.GetVersionStatus()
if err != nil {
return fmt.Errorf("error getting version status: %s", err)
}

if describeOutput == "pretty" {
tool.Print()
Expand Down
50 changes: 42 additions & 8 deletions cmd/uniget/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,24 @@ func installTools(requestedTools tool.Tools, check bool, plan bool, reinstall bo

if reinstall {
logging.Info.Printfln("Reinstalling %s %s", tool.Name, tool.Version)
uninstallTool(tool.Name)
err := uninstallTool(tool.Name)
if err != nil {
logging.Warning.Printfln("Unable to uninstall %s: %s", tool.Name, err)
continue
}

} else if tool.Status.BinaryPresent || tool.Status.MarkerFilePresent {
logging.Info.Printfln("Updating %s %s", tool.Name, tool.Version)
uninstallTool(tool.Name)
printToolUpdate(tool.Name)
err := uninstallTool(tool.Name)
if err != nil {
logging.Warning.Printfln("Unable to uninstall %s: %s", tool.Name, err)
continue
}
err = printToolUpdate(tool.Name)
if err != nil {
logging.Warning.Printfln("Unable to print tool update: %s", err)
continue
}

} else {
logging.Info.Printfln("Installing %s %s", tool.Name, tool.Version)
Expand All @@ -296,9 +308,23 @@ func installTools(requestedTools tool.Tools, check bool, plan bool, reinstall bo
logging.Error.Printfln("Unable to find dependency %s", depName)
return fmt.Errorf("unable to find dependency %s", depName)
}
dep.GetBinaryStatus()
dep.GetMarkerFileStatus(prefix + "/" + cacheDirectory)
dep.GetVersionStatus()

err = dep.GetBinaryStatus()
if err != nil {
logging.Error.Printfln("Unable to get binary status of dependency %s: %s", depName, err)
return fmt.Errorf("unable to get binary status of dependency %s: %s", depName, err)
}
err = dep.GetMarkerFileStatus(prefix + "/" + cacheDirectory)
if err != nil {
logging.Error.Printfln("Unable to get marker file status of dependency %s: %s", depName, err)
return fmt.Errorf("unable to get marker file status of dependency %s: %s", depName, err)
}
err = dep.GetVersionStatus()
if err != nil {
logging.Error.Printfln("Unable to get version status of dependency %s: %s", depName, err)
return fmt.Errorf("unable to get version status of dependency %s: %s", depName, err)
}

if dep.Status.BinaryPresent || dep.Status.MarkerFilePresent {
continue
}
Expand All @@ -313,9 +339,17 @@ func installTools(requestedTools tool.Tools, check bool, plan bool, reinstall bo
continue
}

printToolUsage(tool.Name)
err = printToolUsage(tool.Name)
if err != nil {
logging.Warning.Printfln("Unable to print tool usage: %s", err)
continue
}

tool.CreateMarkerFile(prefix + "/" + cacheDirectory)
err = tool.CreateMarkerFile(prefix + "/" + cacheDirectory)
if err != nil {
logging.Warning.Printfln("Unable to create marker file: %s", err)
continue
}
}

if len(prefix) > 0 {
Expand Down
15 changes: 12 additions & 3 deletions cmd/uniget/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,18 @@ var listCmd = &cobra.Command{
var installedTools tool.Tools
for index := range tools.Tools {
tools.Tools[index].ReplaceVariables(prefix+"/"+target, arch, altArch)
tools.Tools[index].GetMarkerFileStatus(prefix + "/" + cacheDirectory)
tools.Tools[index].GetBinaryStatus()
tools.Tools[index].GetVersionStatus()
err := tools.Tools[index].GetMarkerFileStatus(prefix + "/" + cacheDirectory)
if err != nil {
return fmt.Errorf("error getting marker file status: %s", err)
}
err = tools.Tools[index].GetBinaryStatus()
if err != nil {
return fmt.Errorf("error getting binary status: %s", err)
}
err = tools.Tools[index].GetVersionStatus()
if err != nil {
return fmt.Errorf("error getting version status: %s", err)
}

if tools.Tools[index].Status.VersionMatches {
installedTools.Tools = append(installedTools.Tools, tools.Tools[index])
Expand Down
16 changes: 13 additions & 3 deletions cmd/uniget/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,19 @@ var messageCmd = &cobra.Command{
}

} else {
printToolInternals(toolName)
printToolUsage(toolName)
printToolUpdate(toolName)
err := printToolInternals(toolName)
if err != nil {
return fmt.Errorf("failed to print tool internals: %s", err)
}
err = printToolUsage(toolName)
if err != nil {
return fmt.Errorf("failed to print tool usage: %s", err)
}
err = printToolUpdate(toolName)
if err != nil {
return fmt.Errorf("failed to print tool update: %s", err)
}

fmt.Println()
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/uniget/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ var searchCmd = &cobra.Command{
printer.Checkmark = &pterm.Checkmark{Checked: "✓", Unchecked: " "}
selectedOptions, _ := printer.Show()
if len(selectedOptions) > 0 {
installToolsByName(selectedOptions, false, false, false, false, false)
err := installToolsByName(selectedOptions, false, false, false, false, false)
if err != nil {
return err
}
}

return nil
Expand Down
22 changes: 18 additions & 4 deletions cmd/uniget/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ var uninstallCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("unable to find tool %s: %s", args[0], err)
}
tool.GetBinaryStatus()
tool.GetMarkerFileStatus(prefix + "/" + cacheDirectory)
tool.GetVersionStatus()

err = tool.GetBinaryStatus()
if err != nil {
return fmt.Errorf("unable to get binary status: %s", err)
}
err = tool.GetMarkerFileStatus(prefix + "/" + cacheDirectory)
if err != nil {
return fmt.Errorf("unable to get marker file status: %s", err)
}
err = tool.GetVersionStatus()
if err != nil {
return fmt.Errorf("unable to get version status: %s", err)
}

if !force && !tool.Status.MarkerFilePresent && !tool.Status.BinaryPresent {
pterm.Warning.Printfln("Tool %s is not installed", args[0])
return nil
Expand Down Expand Up @@ -92,7 +103,10 @@ func uninstallTool(toolName string) error {
}
}

tool.RemoveMarkerFile(prefix + "/" + cacheDirectory)
err = tool.RemoveMarkerFile(prefix + "/" + cacheDirectory)
if err != nil {
return fmt.Errorf("unable to remove marker file: %s", err)
}

entries, err := os.ReadDir(prefix + "/" + cacheDirectory + "/" + tool.Name)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion cmd/uniget/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ var upgradeCmd = &cobra.Command{
return fmt.Errorf("failed to find installed tools: %s", err)
}

installTools(requestdTools, false, plan, false, false, false)
err = installTools(requestdTools, false, plan, false, false, false)
if err != nil {
return fmt.Errorf("failed to install tools: %s", err)
}

return nil
},
Expand Down
15 changes: 12 additions & 3 deletions cmd/uniget/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ var versionCmd = &cobra.Command{
return fmt.Errorf("failed to get tool: %s", err)
}
tool.ReplaceVariables(prefix+"/"+target, arch, altArch)
tool.GetMarkerFileStatus(prefix + "/" + cacheDirectory)
tool.GetBinaryStatus()
tool.GetVersionStatus()
err = tool.GetMarkerFileStatus(prefix + "/" + cacheDirectory)
if err != nil {
return fmt.Errorf("failed to get marker file status: %s", err)
}
err = tool.GetBinaryStatus()
if err != nil {
return fmt.Errorf("failed to get binary status: %s", err)
}
err = tool.GetVersionStatus()
if err != nil {
return fmt.Errorf("failed to get version status: %s", err)
}

if !tool.Status.MarkerFilePresent && !tool.Status.BinaryPresent {
pterm.Warning.Printfln("Tool %s is not installed", tool.Name)
Expand Down
6 changes: 5 additions & 1 deletion pkg/archive/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func ExtractTarGz(gzipStream io.Reader) error {
if _, err := io.Copy(outFile, tarReader); err != nil {
return fmt.Errorf("ExtractTarGz: Copy() failed: %s", err.Error())
}
outFile.Chmod(os.FileMode(header.Mode))
mode := os.FileMode(header.Mode)
err = outFile.Chmod(mode)
if err != nil {
return fmt.Errorf("ExtractTarGz: Chmod() failed: %s", err.Error())
}
outFile.Close()

case tar.TypeSymlink:
Expand Down
5 changes: 4 additions & 1 deletion pkg/tool/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ func TestResolveDependencies(t *testing.T) {
}

var plannedTools Tools
tools.ResolveDependencies(&plannedTools, "foo")
err = tools.ResolveDependencies(&plannedTools, "foo")
if err != nil {
t.Errorf("Error resolving dependencies: %s\n", err)
}
if len(plannedTools.Tools) != 2 {
t.Errorf("Expected 2 tools, got %d: %s", len(plannedTools.Tools), strings.Join(plannedTools.GetNames(), ","))
}
Expand Down

0 comments on commit b12322d

Please sign in to comment.