Skip to content

Commit

Permalink
Added raw inspect #151
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasdille committed Dec 22, 2023
1 parent 694c0b5 commit 5ea0d9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/uniget/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var describeCmd = &cobra.Command{
case "Abort":
return nil
case "Inspect":
err = tool.Inspect(registryImagePrefix, altArch)
err = tool.Inspect(registryImagePrefix, altArch, false)
if err != nil {
return fmt.Errorf("unable to inspect %s: %s", tool.Name, err)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/uniget/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
)

var toolVersion string
var rawInspect bool

func initInspectCmd() {
inspectCmd.Flags().StringVar(&toolVersion, "version", "", "Inspect a specific version of the tool")
inspectCmd.Flags().BoolVar(&rawInspect, "raw", false, "Show raw contents")

rootCmd.AddCommand(inspectCmd)
}
Expand Down Expand Up @@ -48,7 +50,7 @@ var inspectCmd = &cobra.Command{
}

logging.Info.Printfln("Inspecting %s %s\n", inspectTool.Name, inspectTool.Version)
err = inspectTool.Inspect(registryImagePrefix, altArch)
err = inspectTool.Inspect(registryImagePrefix, altArch, rawInspect)
if err != nil {
return fmt.Errorf("unable to inspect %s: %s", inspectTool.Name, err)
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/tool/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ func (tool *Tool) Install(registryImagePrefix string, prefix string, target stri
return nil
}

func (tool *Tool) Inspect(registryImagePrefix string, altArch string) error {
func (tool *Tool) Inspect(registryImagePrefix string, altArch string, raw bool) error {
// Fetch manifest for tool
err := containers.GetManifest(fmt.Sprintf(registryImagePrefix+"%s:%s", tool.Name, strings.Replace(tool.Version, "+", "-", -1)), altArch, func(blob blob.Reader) error {
result, err := archive.ListTarGz(blob, func(path string) string {
// Remove prefix usr/local/ to support arbitrary target directories
// Necessary as long as tools are still installed in hardcoded /usr/local
fixedPath := strings.TrimPrefix(path, "usr/local/")
fixedPath := path
if !raw {
fixedPath = strings.TrimPrefix(path, "usr/local/")
}
return fixedPath
})
if err != nil {
Expand Down

0 comments on commit 5ea0d9d

Please sign in to comment.