Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inspector resolve-git-repo command #336

Merged
merged 2 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading