Skip to content

Commit

Permalink
Add inspector resolve-git-repo command (#336)
Browse files Browse the repository at this point in the history
* Add `inspector resolve-git-repo` command

* Bump version in `CHANGELOG.md`
  • Loading branch information
ethanjli authored Dec 8, 2024
1 parent 8e0672b commit 069987b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## 0.8.0-alpha.4 - 2024-12-07

### Added

- (cli) Added a `inspector resolve-git-repo` command to resolve version queries on git repositories.

### Fixed

- (cli) `[dev] plt show-plt-version` and `[dev] plt show-repo-version` no longer require the required pallets/repos to be cached before the commands work.
- (cli) The `[dev] plt show-plt-version` and `[dev] plt show-repo-version` commands no longer require the required pallets/repos to be cached before the respective commands work.

## 0.8.0-alpha.3 - 2024-12-06

Expand Down
2 changes: 1 addition & 1 deletion cmd/forklift/cache/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var Cmd = &cli.Command{
Name: "rm-mir",
Aliases: []string{"remove-mirrors", "del-mir", "delete-mirrors"},
Category: "Modify the cache",
Usage: "Removes locally-cached pallets",
Usage: "Removes local mirrors of git repositories",
// TODO: allow only removing mirrors matching a glob pattern
Action: rmGitRepoAction("mirror", getMirrorCache),
},
Expand Down
21 changes: 21 additions & 0 deletions cmd/forklift/inspector/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Package inspector provides subcommands for inspecting the state of various things
package inspector

import (
"github.com/urfave/cli/v2"
)

var Cmd = &cli.Command{
Name: "inspector",
Usage: "Inspects the state of various things",
Subcommands: []*cli.Command{
{
Name: "resolve-git-repo",
Aliases: []string{"resolve-git-repository"},
Usage: "Prints the version/pseudoversion string for the version query on the specified git " +
"repo",
ArgsUsage: "git_repo_path@version_query",
Action: resolveGitRepoAction,
},
},
}
47 changes: 47 additions & 0 deletions cmd/forklift/inspector/inspector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package inspector

import (
"fmt"

"github.com/pkg/errors"
"github.com/urfave/cli/v2"

"github.com/PlanktoScope/forklift/internal/app/forklift"
fcli "github.com/PlanktoScope/forklift/internal/app/forklift/cli"
)

// resolve-git-repo

func resolveGitRepoAction(c *cli.Context) error {
workspace, err := ensureWorkspace(c.String("workspace"))
if err != nil {
return err
}

query := c.Args().First()
resolved, err := fcli.ResolveQueriesUsingLocalMirrors(
0, workspace.GetMirrorCachePath(), []string{query}, true,
)
if err != nil {
return errors.Wrapf(err, "couldn't resolve query %s", query)
}
fmt.Println(resolved[query].VersionLock.Version)
return nil
}

func ensureWorkspace(wpath string) (*forklift.FSWorkspace, error) {
if !forklift.DirExists(wpath) {
fmt.Printf("Making a new workspace at %s...", wpath)
}
if err := forklift.EnsureExists(wpath); err != nil {
return nil, errors.Wrapf(err, "couldn't make new workspace at %s", wpath)
}
workspace, err := forklift.LoadWorkspace(wpath)
if err != nil {
return nil, err
}
if err = forklift.EnsureExists(workspace.GetDataPath()); err != nil {
return nil, errors.Wrapf(err, "couldn't ensure the existence of %s", workspace.GetDataPath())
}
return workspace, nil
}
2 changes: 2 additions & 0 deletions cmd/forklift/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/PlanktoScope/forklift/cmd/forklift/cache"
"github.com/PlanktoScope/forklift/cmd/forklift/dev"
"github.com/PlanktoScope/forklift/cmd/forklift/host"
"github.com/PlanktoScope/forklift/cmd/forklift/inspector"
"github.com/PlanktoScope/forklift/cmd/forklift/plt"
"github.com/PlanktoScope/forklift/cmd/forklift/stage"
fcli "github.com/PlanktoScope/forklift/internal/app/forklift/cli"
Expand Down Expand Up @@ -54,6 +55,7 @@ var app = &cli.App{
}),
cache.Cmd,
host.Cmd,
inspector.Cmd,
dev.MakeCmd(dev.Versions{
Staging: fcliVersions,
NewStageStore: newStageStoreVersion,
Expand Down

0 comments on commit 069987b

Please sign in to comment.