-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Command Interface #150
Command Interface #150
Conversation
Couple style things, setup your editor to automatically run |
type Command struct { | ||
Help string | ||
Options []Option | ||
f func(*Request) (interface{}, error) |
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.
if we have a Request
object, maybe could return a Response
object too.
looks good so far! |
The recent changes deal with command output. Commands will now be able to output an |
type Error struct { | ||
Message string | ||
Code ErrorType | ||
} |
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.
can make this struct implement the error
interface by adding:
func (e *Error) Error() string {
return fmt.Sprintf("%d error: %s", e.Code, e.Message)
}
http://golang.org/pkg/builtin/#error
And then just use it directly in the Response struct
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.
bump on this. it simplifies the Response
implementation
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.
addressed
LGTM so far. Not sure why travis failed-- maybe try rebasing on master (not sure if up to date) |
cd43433
to
8f1c12e
Compare
@mappum lmk when you want CR / ready to merge in. |
The Next up is refactoring the commands, CLI entry point, and RPC client/server to use this. That is a big change, so it could possibly be in its own PR (and this could now be merged). |
Options []Option | ||
f func(*Request, *Response) | ||
subcommands map[string]*Command | ||
} |
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.
f -> function
(meaningful var name at object level)- make a type for the function
- comments on exported symbols (golint)
// Function is the type of function that Commands use.
// It reads from the Request, and writes results to the Response.
type Function func(*Request, *Response)
// Command is a runnable command, with input arguments and options (flags).
// It can also have subcommands, to group units of work into sets.
type Command struct {
Help string
Options []Option
function Function
subcommands map[string]*Command
}
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.
addressed
@mappum rebased on top of new master. |
@mappum: one comment re one caveat i have on this is i think that the |
actually, hang on. it may not be needed, given that it's cumbersome to define it statically, and we may want functions to help us with making options etc: // in a function
cmdIpfsPin = &commands.Command{
Description: "pin ipfs objects to local storage.",
Help: `Manages ipfs objects pinned to (kept in) local storage.`,
Options: []Option{
Option{[]string{"r", "recursive"}, commands.Bool},
},
Run: func(req Request, res Response) { ... },
Subcommands: map[string]*Command{
"add": cmdIpfsPinAdd,
"rm": cmdIpfsPinRm,
}
} or var cmdIpfsPin = &cmd.Command{
Description: "pin ipfs objects to local storage.",
Help: `Manages ipfs objects pinned to (kept in) local storage.`,
Options: []Option{
cmd.MakeOption(cmd.Bool, "pin objects recursively", "r", "recursive")
},
Run: func(req Request, res Response) { ... },
}
cmdIpfsPin.Register("add", cmdIpfsPinAdd)
cmdIpfsPin.Register("rm", cmdIpfsPinRm)
// I really dont like this o/ it makes it easier to change commands after startup, or
// to move this Register call elsewhere in the code. And, autogenerating the "subcommands" part of the help from the subcommands map won't work well: it won't let us specify order. |
@mappum: did you opt for keeping a separate Stream instead of assigning to the same value? ok, let's merge this and see how the interface has to change when we fit the other commands to it. |
Add explanation to NewDHT/NewDHTClient doc strings
* remove the EnableRelayHop option in the SwarmConfig * add an option to disable the limited relay * make the relay service resources configurable * refactor: use custom types This enables us to swap defaults in go-ipfs without touching the config file generated during `ipfs init` ipfs/go-ipfs-config#146 (comment) ipfs/go-ipfs-config#146 (comment) * use OptionalDuration in RelayService configuration * fix: *OptionalInteger with omitempty This removes null values from the config * fix: Flag does not need to be a pointer * refactor: flatten RelayService limits this simplifies consumer code and removes nil footgun * docs: clarify different relay types * feat: flag for ForceReachability mode in libp2p (ipfs#150) adds Internal.Libp2pForceReachability needed for sharness tests in ipfs#8522 Co-authored-by: Marcin Rataj <lidel@lidel.org> Co-authored-by: Marcin Rataj <lidel@lidel.org>
* remove the EnableRelayHop option in the SwarmConfig * add an option to disable the limited relay * make the relay service resources configurable * refactor: use custom types This enables us to swap defaults in go-ipfs without touching the config file generated during `ipfs init` ipfs/go-ipfs-config#146 (comment) ipfs/go-ipfs-config#146 (comment) * use OptionalDuration in RelayService configuration * fix: *OptionalInteger with omitempty This removes null values from the config * fix: Flag does not need to be a pointer * refactor: flatten RelayService limits this simplifies consumer code and removes nil footgun * docs: clarify different relay types * feat: flag for ForceReachability mode in libp2p (ipfs#150) adds Internal.Libp2pForceReachability needed for sharness tests in ipfs#8522 Co-authored-by: Marcin Rataj <lidel@lidel.org> Co-authored-by: Marcin Rataj <lidel@lidel.org>
* remove the EnableRelayHop option in the SwarmConfig * add an option to disable the limited relay * make the relay service resources configurable * refactor: use custom types This enables us to swap defaults in go-ipfs without touching the config file generated during `ipfs init` ipfs/go-ipfs-config#146 (comment) ipfs/go-ipfs-config#146 (comment) * use OptionalDuration in RelayService configuration * fix: *OptionalInteger with omitempty This removes null values from the config * fix: Flag does not need to be a pointer * refactor: flatten RelayService limits this simplifies consumer code and removes nil footgun * docs: clarify different relay types * feat: flag for ForceReachability mode in libp2p (ipfs#150) adds Internal.Libp2pForceReachability needed for sharness tests in ipfs#8522 Co-authored-by: Marcin Rataj <lidel@lidel.org> Co-authored-by: Marcin Rataj <lidel@lidel.org>
* remove the EnableRelayHop option in the SwarmConfig * add an option to disable the limited relay * make the relay service resources configurable * refactor: use custom types This enables us to swap defaults in go-ipfs without touching the config file generated during `ipfs init` ipfs/go-ipfs-config#146 (comment) ipfs/go-ipfs-config#146 (comment) * use OptionalDuration in RelayService configuration * fix: *OptionalInteger with omitempty This removes null values from the config * fix: Flag does not need to be a pointer * refactor: flatten RelayService limits this simplifies consumer code and removes nil footgun * docs: clarify different relay types * feat: flag for ForceReachability mode in libp2p (ipfs#150) adds Internal.Libp2pForceReachability needed for sharness tests in ipfs#8522 Co-authored-by: Marcin Rataj <lidel@lidel.org> Co-authored-by: Marcin Rataj <lidel@lidel.org>
This isn't ready for merge yet, PRing for code review/comments.