func TestOptionParsing(t *testing.T) { subCmd := &commands.Command{} cmd := &commands.Command{ Options: []commands.Option{ commands.StringOption("b", "some option"), }, Subcommands: map[string]*commands.Command{ "test": subCmd, }, } opts, input, err := parseOptions([]string{"--beep", "-boop=lol", "test2", "-c", "beep", "--foo=5"}) /*for k, v := range opts { fmt.Printf("%s: %s\n", k, v) } fmt.Printf("%s\n", input)*/ if err != nil { t.Error("Should have passed") } if len(opts) != 4 || opts["beep"] != "" || opts["boop"] != "lol" || opts["c"] != "" || opts["foo"] != "5" { t.Errorf("Returned options were defferent than expected: %v", opts) } if len(input) != 2 || input[0] != "test2" || input[1] != "beep" { t.Errorf("Returned input was different than expected: %v", input) } _, _, err = parseOptions([]string{"-beep=1", "-boop=2", "-beep=3"}) if err == nil { t.Error("Should have failed (duplicate option name)") } path, args, sub := parsePath([]string{"test", "beep", "boop"}, cmd) if len(path) != 1 || path[0] != "test" { t.Errorf("Returned path was defferent than expected: %v", path) } if len(args) != 2 || args[0] != "beep" || args[1] != "boop" { t.Errorf("Returned args were different than expected: %v", args) } if sub != subCmd { t.Errorf("Returned command was different than expected") } }
IPNS mounted at: /ipns > cd /ipfs/QmSh5e7S6fdcu75LAbXNZAFY2nGyZUJXyLCJDvn2zRkWyC > ls bar > cat bar baz > cat /ipfs/QmSh5e7S6fdcu75LAbXNZAFY2nGyZUJXyLCJDvn2zRkWyC/bar baz > cat /ipfs/QmWLdkp93sNxGRjnFHPaYg8tCQ35NBY3XPn6KiETd3Z4WR baz `, }, Options: []cmds.Option{ // TODO longform cmds.StringOption("f", "The path where IPFS should be mounted"), // TODO longform cmds.StringOption("n", "The path where IPNS should be mounted"), }, Run: func(req cmds.Request) (interface{}, error) { cfg, err := req.Context().GetConfig() if err != nil { return nil, err } node, err := req.Context().GetNode() if err != nil { return nil, err }
daemon Start a long-running daemon process mount Mount an ipfs read-only mountpoint serve Serve an interface to ipfs diag Print diagnostics Plumbing commands: block Interact with raw blocks in the datastore object Interact with raw dag nodes Use 'ipfs <command> --help' to learn more about each command. `, }, Options: []cmds.Option{ cmds.StringOption("config", "c", "Path to the configuration file to use"), cmds.BoolOption("debug", "D", "Operate in debug mode"), cmds.BoolOption("help", "Show the full command help text"), cmds.BoolOption("h", "Show a short version of the command help text"), cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon"), }, } // commandsDaemonCmd is the "ipfs commands" command for daemon var CommandsDaemonCmd = CommandsCmd(Root) var rootSubcommands = map[string]*cmds.Command{ "cat": CatCmd, "ls": lsCmd, "commands": CommandsDaemonCmd, "name": nameCmd,
`, LongDescription: ` Returns a list of hashes of objects being pinned. Objects that are indirectly or recursively pinned are not included in the list. Use --type=<type> to specify the type of pinned keys to list. Valid values are: * "direct" * "indirect" * "recursive" * "all" (Defaults to "direct") `, }, Options: []cmds.Option{ cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\". Defaults to \"direct\""), }, Run: func(req cmds.Request) (interface{}, error) { n, err := req.Context().GetNode() if err != nil { return nil, err } typeStr, found, err := req.Option("type").String() if err != nil { return nil, err } if !found { typeStr = "direct" }