Skip to content

Commit

Permalink
add back lakeSpecified
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnibs committed Oct 4, 2023
1 parent 3db2df4 commit eb32514
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
18 changes: 11 additions & 7 deletions cli/lakeflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Flags struct {
ConfigDir string
Lake string
Quiet bool

lakeSpecified bool
}

func (l *Flags) SetFlags(fs *flag.FlagSet) {
Expand All @@ -33,12 +35,10 @@ func (l *Flags) SetFlags(fs *flag.FlagSet) {
}
fs.StringVar(&l.ConfigDir, "configdir", dir, "configuration and credentials directory")
if s, ok := os.LookupEnv("ZED_LAKE"); ok {
l.Lake = strings.TrimRight(s, "/")
} else {
l.Lake = defaultDataDir
l.Lake, l.lakeSpecified = s, true
}
fs.Func("lake", fmt.Sprintf("lake location (env ZED_LAKE) (default %s)", l.Lake), func(s string) error {
l.Lake = strings.TrimRight(s, "/")
l.Lake, l.lakeSpecified = s, true
return nil
})
}
Expand Down Expand Up @@ -82,10 +82,14 @@ func (l *Flags) AuthStore() *auth0.Store {
}

func (l *Flags) URI() (*storage.URI, error) {
if l.Lake == "" {
lk := strings.TrimRight(l.Lake, "/")
if !l.lakeSpecified {
lk = defaultDataDir
}
if lk == "" {
return nil, errors.New("lake location must be set (either with the -lake flag or ZED_LAKE environment variable)")
}
u, err := storage.ParseURI(l.Lake)
u, err := storage.ParseURI(lk)
if err != nil {
err = fmt.Errorf("error parsing lake location: %w", err)
}
Expand All @@ -100,7 +104,7 @@ func (l *Flags) ClientURI() (*storage.URI, error) {
if err != nil {
return nil, err
}
if u.String() == storage.MustParseURI(defaultDataDir).String() && localServer() {
if !l.lakeSpecified && localServer() {
u = storage.MustParseURI("http://localhost:9867")
}
return u, nil
Expand Down
24 changes: 15 additions & 9 deletions cmd/zed/init/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/brimdata/zed/cmd/zed/root"
"github.com/brimdata/zed/lake/api"
"github.com/brimdata/zed/pkg/charm"
"github.com/brimdata/zed/pkg/storage"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -35,23 +36,28 @@ func (c *Command) Run(args []string) error {
return err
}
defer cleanup()
var path string
var u *storage.URI
if len(args) == 0 {
path = c.LakeFlags.Lake
if u, err = c.LakeFlags.URI(); err != nil {
return err
}
} else if len(args) == 1 {
path = args[0]
path := args[0]
if path == "" {
return errors.New("single lake path argument required")
}
if u, err = storage.ParseURI(path); err != nil {
return err
}
}
if path == "" {
return errors.New("single lake path argument required")
}
if api.IsLakeService(path) {
if api.IsLakeService(u.String()) {
return fmt.Errorf("init command not valid on remote lake")
}
if _, err := api.CreateLocalLake(ctx, zap.Must(zap.NewProduction()), path); err != nil {
if _, err := api.CreateLocalLake(ctx, zap.Must(zap.NewProduction()), u.String()); err != nil {
return err
}
if !c.LakeFlags.Quiet {
fmt.Printf("lake created: %s\n", path)
fmt.Printf("lake created: %s\n", u)
}
return nil
}
4 changes: 2 additions & 2 deletions cmd/zed/ztests/xdg-data-home.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ script: |
outputs:
- name: stdout
data: |
lake created: path/to/lake/zed
regexp: |
lake created: file:.*path/to/lake/zed

0 comments on commit eb32514

Please sign in to comment.