Skip to content
6 changes: 4 additions & 2 deletions cmd/warpforge/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -329,6 +330,7 @@ func cmdCatalogBundle(c *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to get pwd: %s", err)
}
pwd = pwd[1:] // Drop leading slash, for use with fs package.

plot, err := dab.PlotFromFile(fsys, filepath.Join(pwd, dab.MagicFilename_Plot))
if err != nil {
Expand All @@ -339,8 +341,8 @@ func cmdCatalogBundle(c *cli.Context) error {

catalogPath := filepath.Join(pwd, ".warpforge", "catalog")
// create a catalog if it does not exist
if _, err = os.Stat(catalogPath); os.IsNotExist(err) {
err = os.MkdirAll(catalogPath, 0755)
if _, err = fs.Stat(fsys, catalogPath); os.IsNotExist(err) {
err = os.MkdirAll("/"+catalogPath, 0755)
if err != nil {
return fmt.Errorf("failed to create catalog directory: %s", err)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/warpforge/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func cmdRun(c *cli.Context) error {
if err != nil {
return fmt.Errorf("could not get current directory")
}
pwd = pwd[1:] // Drop leading slash, for use with fs package.
_, err = execModule(ctx, fsys, config, filepath.Join(pwd, dab.MagicFilename_Module))
if err != nil {
return err
Expand Down
15 changes: 10 additions & 5 deletions cmd/warpforge/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func cmdStatus(c *cli.Context) error {
if err != nil {
return fmt.Errorf("could not get current directory")
}
pwd = pwd[1:] // Drop leading slash, for use with fs package.

// display version
if verbose {
Expand Down Expand Up @@ -95,6 +96,10 @@ func cmdStatus(c *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to open module file: %s", err)
}
} else if os.IsNotExist(err) {
Copy link
Copy Markdown
Collaborator

@TripleDogDare TripleDogDare Aug 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if-else block should be re-written to make the else statements go away.

// fine; it can just not exist.
} else {
return err
}

if isModule {
Expand Down Expand Up @@ -173,20 +178,20 @@ func cmdStatus(c *cli.Context) error {
}

// handle special case for pwd
fmt.Fprintf(c.App.Writer, "\t%s (pwd", pwd)
fmt.Fprintf(c.App.Writer, "\t/%s (pwd", pwd)
if isModule {
fmt.Fprintf(c.App.Writer, ", module")
}
// check if it's a workspace
if _, err := os.Stat(filepath.Join(pwd, ".warpforge")); !os.IsNotExist(err) {
if _, err := fs.Stat(fsys, filepath.Join(pwd, ".warpforge")); !os.IsNotExist(err) {
fmt.Fprintf(c.App.Writer, ", workspace")
}
// check if it's a root workspace
if _, err := os.Stat(filepath.Join(pwd, ".warpforge/root")); !os.IsNotExist(err) {
if _, err := fs.Stat(fsys, filepath.Join(pwd, ".warpforge/root")); !os.IsNotExist(err) {
fmt.Fprintf(c.App.Writer, ", root workspace")
}
// check if it's a git repo
if _, err := os.Stat(filepath.Join(pwd, ".git")); !os.IsNotExist(err) {
if _, err := fs.Stat(fsys, filepath.Join(pwd, ".git")); !os.IsNotExist(err) {
fmt.Fprintf(c.App.Writer, ", git repo")
}

Expand All @@ -197,7 +202,7 @@ func cmdStatus(c *cli.Context) error {
fs, subPath := ws.Path()
path := fmt.Sprintf("%s%s", fs, subPath)

if path == pwd {
if path == "/"+pwd {
// we handle pwd earlier, ignore
continue
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/warpforge/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func binPath(bin string) (string, error) {
// root workspace: the first marked root workspace in the stack, or the home workspace if none are marked,
// home workspace: the workspace at the user's homedir
func openWorkspaceSet(fsys fs.FS) (workspace.WorkspaceSet, error) {
pwd, err := os.Getwd()
pwd, err := os.Getwd() // FIXME why are you doing this again? you almost certainly already did it moments ago.
if err != nil {
return workspace.WorkspaceSet{}, fmt.Errorf("failed to get working directory: %s", err)
}
Expand Down