Skip to content

Commit

Permalink
create: support './' and abs for protofile path
Browse files Browse the repository at this point in the history
  • Loading branch information
WineChord committed Oct 20, 2023
1 parent a5e4c51 commit c4f0554
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/create/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -165,6 +166,8 @@ func (c *Create) fixProtoDirs() error {

if c.options.UseBaseName {
c.options.Protofile = filepath.Base(target)
} else if filepath.IsAbs(c.options.Protofile) {
c.options.Protofile = strings.TrimPrefix(c.options.Protofile, "/")
}

c.options.ProtofileAbs = target
Expand Down Expand Up @@ -408,12 +411,13 @@ func (c *Create) parsePBIDLOptions(flags *pflag.FlagSet) error {
if err != nil {
return fmt.Errorf("flags get protodir string array failed err: %w", err)
}
// Always append the current working directory.
c.options.Protodirs = fs.UniqFilePath(append(dirs, "."))
// Always append the current working directory and root directory.
c.options.Protodirs = fs.UniqFilePath(append(dirs, ".", "/"))
c.options.Protofile, err = flags.GetString("protofile")
if err != nil {
return fmt.Errorf("flags get protofile string failed err: %w", err)
}
c.options.Protofile = filepath.Clean(c.options.Protofile)
c.options.Gotag, err = flags.GetBool("gotag")
if err != nil {
return fmt.Errorf("flags get gotag bool failed err: %w", err)
Expand Down

0 comments on commit c4f0554

Please sign in to comment.