-
Notifications
You must be signed in to change notification settings - Fork 5
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
Extracting filesystem accesses; 'workspace inspect' command #13
Draft
warpfork
wants to merge
9
commits into
master
Choose a base branch
from
extracting-dabs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a641316
Extracting filesystem access better.
warpfork 45e4552
Fix some regressions from the conversions to using fs.FS.
warpfork f8c6210
Begin outlining a 'workspace inspect' command.
warpfork 8fdb3c6
Hoist out a ComputeStats func for plots.
warpfork 0f16955
ComputeStats on a plot needs to be recursive!
warpfork fd29e04
Appease error analyzer.
warpfork 450b5e6
'workspace inspect' command now generates many checkmarks.
warpfork 5b9f07d
'workspace inspect' now has valence opinions on these checkboxes.
warpfork 0fbe91a
'workspace inspect' attempts to align output now.
warpfork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/warpfork/warpforge/pkg/dab" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var cmdDefWorkspaceInspect = cli.Command{ | ||
Name: "inspect", | ||
Usage: "Inspect and report upon the situation of the current workspace (how many modules are there, have we got a cached evaluation of them, etc).", | ||
Action: cmdFnWorkspaceInspect, | ||
// Aliases: []string{"winspect"}, // doesn't put them at the top level. Womp. | ||
} | ||
|
||
func cmdFnWorkspaceInspect(c *cli.Context) error { | ||
fsys := os.DirFS("/") | ||
|
||
// First, find the workspace. | ||
wss, err := openWorkspaceSet(fsys) | ||
if err != nil { | ||
return fmt.Errorf("failed to open workspace set: %s", err) | ||
} | ||
|
||
// Briefly report on the nearest workspace. | ||
// (We could talk about the grandparents too, but 'wf status' already does that; here we want to focus more on contents than parentage.) | ||
wsFs, wsPath := wss.Stack[0].Path() | ||
fmt.Fprintf(c.App.Writer, "Workspace: %s%s\n", wsFs, wsPath) | ||
|
||
// Search for modules within the workspace. | ||
fs.WalkDir(wsFs, wsPath, func(path string, d fs.DirEntry, err error) error { | ||
// fmt.Fprintf(c.App.Writer, "hi: %s%s\n", wsFs, path) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Don't ever look into warpforge guts directories. | ||
if d.Name() == dab.MagicFilename_Workspace { | ||
return fs.SkipDir | ||
} | ||
|
||
// If this is a dir (beyond the root): look see if it contains a workspace marker. | ||
// If it does, we might not want to report on it. | ||
// TODO: a bool flag for this. | ||
if d.IsDir() && len(path) > len(wsPath) { | ||
_, e2 := fs.Stat(wsFs, filepath.Join(path, dab.MagicFilename_Workspace)) | ||
if e2 == nil || os.IsNotExist(e2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. invert if block to get rid of else statement. |
||
// carry on | ||
} else { | ||
return fs.SkipDir | ||
} | ||
} | ||
|
||
// Peek for module file. | ||
if d.Name() == dab.MagicFilename_Module { | ||
modPathWithinWs := path[len(wsPath)+1 : len(path)-len(dab.MagicFilename_Module)] // leave the trailing slash on. For disambig in case we support multiple module files per dir someday. | ||
mod, err := dab.ModuleFromFile(wsFs, path) | ||
modName := mod.Name | ||
if err != nil { | ||
modName = "!!Unknown!!" | ||
} | ||
|
||
// Tell me about it. | ||
fmt.Fprintf(c.App.Writer, "Module found: %q -- at path %q\n", modName, modPathWithinWs) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package dab | ||
|
||
const ( | ||
MagicFilename_Workspace = ".warpforge" | ||
) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider making this whole block a function.