-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
inspector resolve-git-repo
command (#336)
* Add `inspector resolve-git-repo` command * Bump version in `CHANGELOG.md`
- Loading branch information
Showing
5 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters