storj/cmd/uplinkng/main.go
Jeff Wendling ef7b89cc03 cmd/uplinkng: remove global flags
this changes globalFlags to be a ulext.External
interface value that is passed to each command.

rather than have the ulext.External have a Setup
call in the way that the projectProvider used to
we make all of the state arguments to the functions
and have the commands call setup themselves.

the reason it is in its own package is so that
cmd/uplinkng can import cmd/uplinkng/ultest
but cmd/uplinkng/ultest needs to refer to whatever
the interface type is to call the function that
creates the commands.

there's also quite a bit of shuffling around of
code and names. sorry if that makes it tricky
to review. there should be no logic changes, though.

a side benefit is there's no longer a need to do
a type assertion in ultest to make it set the
fake filesystem to use. that can be passed in
directly now. additionally, this makes the
access commands much easier to test.

Change-Id: I29cf6a2144248a58b7a605a7ae0a5ada5cfd57b6
2021-07-06 17:26:51 -04:00

58 lines
1.8 KiB
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"flag"
"fmt"
"os"
"github.com/zeebo/clingy"
_ "storj.io/private/process"
"storj.io/storj/cmd/uplinkng/ulext"
)
func main() {
ex := newExternal()
ok, err := clingy.Environment{
Name: "uplink",
Args: os.Args[1:],
Dynamic: ex.Dynamic,
Wrap: ex.Wrap,
}.Run(context.Background(), func(cmds clingy.Commands) {
ex.Setup(cmds) // setup ex first so that stdlib flags can consult config
newStdlibFlags(flag.CommandLine).Setup(cmds)
commands(cmds, ex)
})
if err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
}
if !ok || err != nil {
os.Exit(1)
}
}
func commands(cmds clingy.Commands, ex ulext.External) {
cmds.Group("access", "Access related commands", func() {
cmds.New("save", "Save an existing access", newCmdAccessSave(ex))
cmds.New("create", "Create an access from a setup token", newCmdAccessCreate(ex))
cmds.New("delete", "Delete an access from local store", newCmdAccessDelete(ex))
cmds.New("list", "List saved accesses", newCmdAccessList(ex))
cmds.New("use", "Set default access to use", newCmdAccessUse(ex))
cmds.New("revoke", "Revoke an access", newCmdAccessRevoke(ex))
})
cmds.New("share", "Shares restricted accesses to objects", newCmdShare(ex))
cmds.New("mb", "Create a new bucket", newCmdMb(ex))
cmds.New("rb", "Remove a bucket bucket", newCmdRb(ex))
cmds.New("cp", "Copies files or objects into or out of tardigrade", newCmdCp(ex))
cmds.New("ls", "Lists buckets, prefixes, or objects", newCmdLs(ex))
cmds.New("rm", "Remove an object", newCmdRm(ex))
cmds.Group("meta", "Object metadata related commands", func() {
cmds.New("get", "Get an object's metadata", newCmdMetaGet(ex))
})
cmds.New("version", "Prints version information", newCmdVersion())
}