-
-
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
Migrate to cobra CLI system #123
Conversation
} | ||
|
||
func lsCmd(c *commander.Command, inp []string) error { | ||
func init() { | ||
CmdIpfs.AddCommand(cmdIpfsLs) |
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.
for readability, may want to perform registration in a single spot. easier to see everything that's registered.
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.
centralization also provides ability to choose which commands to include, exclude
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.
commands should hold their children, as before. sometimes one command may be pointed at by multiple parents. and this should be fine.
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.
(also makes it really easy to break out subcommands into independent packages that can then be used by other tools (say ipfs name
and ipns
are the same cmd)
} | ||
|
||
func addCmd(c *commander.Command, inp []string) error { | ||
func addCmd(c *cobra.Command, inp []string) { |
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.
how does cobra return errors? it just prints them out itself??? (arghhh).
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.
this bothers me.... fork?fork?fork?
thanks @mappum! made comments up there. i think a lot of these changes are bad for how I want to structure the composability of code. particularly:
lesser (annoying but whatever) issues:
if cobra doesn't allow us to do this, then the global flags thing is really not worth it. one of the reasons i chose & forked
let's wait for thoughts from others, and then either |
A better solution might be to work on a command system that supports commands through multiple transports (CLI, HTTP RPC, raw TCP RPC), and multiple encodings, then just build a CLI system that adheres to that That would make adding new commands extremely easy since you can just implement it in one place, and not have to make wrapper CLI/HTTP/etc handlers just to call each command. |
Yeah, I like the sound of this. Can you sketch out what the interfaces would look like?
Yep. Though the devil's in the details (i.e. CLI cmds will still need independent handlers to ensure that the command makes sense to type as a human, and HTTP handlers may still be needed to ensure things still make sense to curl manually, etc etc. I.e. these abstractions are in general really good, and of course it is critical to put in place a common interface they all use (to ensure no logic gets duplicated), but often the automatic, abstract thing is too general to make sense for the UX. So a custom wrapper handler will most likely still be needed to make things nice and usable by humans) |
@mappum @whyrusleeping so what do we do here-- hack our own package to do this? fork cobra to do what we want? |
I think we can fork it. The changes that need to be made arent huge, and we could even name it something like "Taipan: more dangerous than cobra", or alternatively, since we would be fixing error handling "Anaconda: Probably less dangerous than cobra" |
@whyrusleeping haha yes. +9001 to either of those names. |
cd43433
to
8f1c12e
Compare
Set KeysOnly field of query condition to true for Datastore.Query(), then it will query only keys.
Refactored the CLI commands to use cobra. Nothing outside of the
main
package (the CLI entry point/commands) is changed by this PR.Addresses #111
ipfs help <cmd>
ipfs add -r
oripfs add --recursive
--config
flag is persistent and can be accessed by any subcommand