Skip to content
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

Commands Refactor Part 2 #263

Closed
wants to merge 384 commits into from
Closed

Commands Refactor Part 2 #263

wants to merge 384 commits into from

Conversation

jbenet
Copy link
Member

@jbenet jbenet commented Nov 4, 2014

We split #196 in two parts. this is the second. (#262 is the first). This builds on all the changes to commands/.

@jbenet jbenet mentioned this pull request Nov 4, 2014
@jbenet
Copy link
Member Author

jbenet commented Nov 4, 2014

warning

Rebasing this on top of master once #262 lands.

@jbenet
Copy link
Member Author

jbenet commented Nov 4, 2014

okay, this should be ready. cc @mappum @maybebtc

@btc
Copy link
Contributor

btc commented Nov 4, 2014

thanks for the git ninja work. very much appreciated.

will have a look

@jbenet
Copy link
Member Author

jbenet commented Nov 4, 2014

This branch's diff --stat master

 Makefile                   |   5 ++
 cmd/ipfs2/.gitignore       |   2 +
 cmd/ipfs2/Makefile         |   7 ++
 cmd/ipfs2/README.md        |  29 +++++++++
 cmd/ipfs2/daemon.go        |  63 ++++++++++++++++++
 cmd/ipfs2/equinox.yaml     |   6 ++
 cmd/ipfs2/init.go          | 157 ++++++++++++++++++++++++++++++++++++++++++++
 cmd/ipfs2/ipfs.go          |  15 +++++
 cmd/ipfs2/main.go          | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 core/commands2/add.go      |  90 ++++++++++++++++++++++++++
 core/commands2/cat.go      |  39 +++++++++++
 core/commands2/commands.go |  59 +++++++++++++++++
 core/commands2/log.go      |  30 +++++++++
 core/commands2/ls.go       |  78 ++++++++++++++++++++++
 core/commands2/publish.go  |  72 +++++++++++++++++++++
 core/commands2/root.go     | 127 ++++++++++++++++++++++++++++++++++++
 daemon2/daemon.go          |  25 +++++++
 server/http/http.go        |   2 +
 18 files changed, 1040 insertions(+)

@jbenet
Copy link
Member Author

jbenet commented Nov 4, 2014

@btc
Copy link
Contributor

btc commented Nov 4, 2014

@jbenet @mappum
question regarding ipfs versus ipfs2. ipfs prints help text when no arguments provided. This is kinda helpful. Do we want the same from the new cli? (Presently, shows no message. see image below)

image

From here forward, will mark my comments with TODO checklists to help track state.

  • 🐯

@jbenet
Copy link
Member Author

jbenet commented Nov 4, 2014

Yes, we definitely want help text printed out.

res.SetError(err, cmds.ErrNormal)
return
}
ctx.Node = node
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mappum

Does this assignment have a side-effect?

Read further and realized the context is passed to the handler with the node in tow.

Is there a plan for removing IPFS-specific concepts from the commands.Context? Doesn't seem like this library could be extracted otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's the reason I kept all the IPFS-specific stuff contained in the Context, but I'm not sure exactly how we should do it. Maybe I should just change it to a map[string]interface{}? Anyway, I'm not too worried about making the library vendorable right away since making it work with IPFS is higher priority.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree. Let's try to not introduce more ipfs specific things and vendor later


Sent from Mailbox

On Tue, Nov 4, 2014 at 3:30 PM, Matt Bell notifications@github.com
wrote:

+func daemonFunc(res cmds.Response, req cmds.Request) {

  • ctx := req.Context()
  • lk, err := daemon.Lock(ctx.ConfigRoot)
  • if err != nil {
  •    res.SetError(fmt.Errorf("Couldn't obtain lock. Is another daemon already running?"), cmds.ErrNormal)
    
  •    return
    
  • }
  • defer lk.Close()
  • node, err := core.NewIpfsNode(ctx.Config, true)
  • if err != nil {
  •    res.SetError(err, cmds.ErrNormal)
    
  •    return
    
  • }
  • ctx.Node = node
    Yep, that's the reason I kept all the IPFS-specific stuff contained in the Context, but I'm not sure exactly how we should do it. Maybe I should just change it to a map[string]interface{}? Anyway, I'm not too worried about making the library vendorable right away since making it work with IPFS is higher priority.

Reply to this email directly or view it on GitHub:
https://github.com/jbenet/go-ipfs/pull/263/files#r19845198

@btc
Copy link
Contributor

btc commented Nov 4, 2014

@mappum

These argument hints are quite helpful.

ipfs

    cmdIpfsInit.Flag.Int("b", 4096, "number of bits for keypair")
    cmdIpfsInit.Flag.String("p", "", "passphrase for encrypting keys")
    cmdIpfsInit.Flag.Bool("f", false, "force overwrite of existing config")
    cmdIpfsInit.Flag.String("d", "", "Change default datastore location")

ipfs2

        cmds.Option{[]string{"bits", "b"}, cmds.Int},
        cmds.Option{[]string{"passphrase", "p"}, cmds.String},
        cmds.Option{[]string{"force", "f"}, cmds.Bool},
        cmds.Option{[]string{"datastore", "d"}, cmds.String},

image

  • 🐯 displaying argument hints in UX
  • 🐯 providing argument hint in commands.Option

// log is the command logger
var log = u.Logger("cmd/ipfs")

func main() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@jbenet
Copy link
Member Author

jbenet commented Nov 5, 2014

@mappum @maybebtc how's it going over here?

@mappum
Copy link
Contributor

mappum commented Nov 5, 2014

Other than generating the proper help text, a lot of the commands are done:

  • add
  • cat
  • commands
  • daemon
  • diag
  • init
  • log
  • ls
  • name
    • publish
    • resolve
  • pin
  • unpin
  • version
  • block
  • bootstrap
  • config
  • mount
  • objects
  • tour
  • update

func createRequest(args []string) (cmds.Request, *cmds.Command) {
req, root, cmd, err := cmdsCli.Parse(args, Root, commands.Root)
if err != nil {
fmt.Println(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mappum Is the class of errors returned by Parse designed around user readability?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, since its input is coming from the user.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mappum sgtm

output := make([]Object, len(req.Arguments()))

for i, arg := range req.Arguments() {
path := arg.(string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast safely

@jbenet
Copy link
Member Author

jbenet commented Nov 6, 2014

Other than generating the proper help text, a lot of the commands are done:

Awesome! I'll CR in a bit.

jbenet and others added 23 commits November 13, 2014 22:54
License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
(The file path is omitted, but since only one object can be added at a time, I think this is ok)
btc pushed a commit that referenced this pull request Nov 14, 2014
@jbenet
Copy link
Member Author

jbenet commented Nov 14, 2014

Closed in favor of #332

@jbenet jbenet closed this Nov 14, 2014
@jbenet jbenet removed the status/in-progress In progress label Nov 14, 2014
@btc btc deleted the cmd-ref-part2 branch January 21, 2015 01:02
ariescodescream pushed a commit to ariescodescream/go-ipfs that referenced this pull request Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants