func getQuery(req cmds.Request) (string, error) { query := url.Values{} for k, v := range req.Options() { if OptionSkipMap[k] { continue } str := fmt.Sprintf("%v", v) query.Set(k, str) } args := req.Arguments() argDefs := req.Command().Arguments argDefIndex := 0 for _, arg := range args { argDef := argDefs[argDefIndex] // skip ArgFiles for argDef.Type == cmds.ArgFile { argDefIndex++ argDef = argDefs[argDefIndex] } query.Add("arg", arg) if len(argDefs) > argDefIndex+1 { argDefIndex++ } } return query.Encode(), nil }
func tourRunFunc(req cmds.Request, res cmds.Response) { cfg, err := req.InvocContext().GetConfig() if err != nil { res.SetError(err, cmds.ErrNormal) return } id := tour.TopicID(cfg.Tour.Last) if len(req.Arguments()) > 0 { id = tour.TopicID(req.Arguments()[0]) } w := new(bytes.Buffer) t, err := tourGet(id) if err != nil { // If no topic exists for this id, we handle this error right here. // To help the user achieve the task, we construct a response // comprised of... // 1) a simple error message // 2) the full list of topics fmt.Fprintln(w, "ERROR") fmt.Fprintln(w, err) fmt.Fprintln(w, "") fprintTourList(w, tour.TopicID(cfg.Tour.Last)) res.SetOutput(w) return } fprintTourShow(w, t) res.SetOutput(w) }
func setDataCaller(req cmds.Request, root *dag.Node) (key.Key, error) { if len(req.Arguments()) < 3 { return "", fmt.Errorf("not enough arguments for set-data") } nd, err := req.InvocContext().GetNode() if err != nil { return "", err } root.Data = []byte(req.Arguments()[2]) newkey, err := nd.DAG.Add(root) if err != nil { return "", err } return newkey, nil }
func rmLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) { if len(req.Arguments()) < 3 { return "", fmt.Errorf("not enough arguments for rm-link") } nd, err := req.InvocContext().GetNode() if err != nil { return "", err } path := req.Arguments()[2] e := dagutils.NewDagEditor(nd.DAG, root) err = e.RmLink(req.Context(), path) if err != nil { return "", err } nnode := e.GetNode() return nnode.Key() }
func rmLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) { if len(req.Arguments()) < 3 { return "", fmt.Errorf("not enough arguments for rm-link") } nd, err := req.InvocContext().GetNode() if err != nil { return "", err } name := req.Arguments()[2] err = root.RemoveNodeLink(name) if err != nil { return "", err } newkey, err := nd.DAG.Add(root) if err != nil { return "", err } return newkey, nil }
func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) { if len(req.Arguments()) < 4 { return "", fmt.Errorf("not enough arguments for add-link") } nd, err := req.InvocContext().GetNode() if err != nil { return "", err } path := req.Arguments()[2] childk := key.B58KeyDecode(req.Arguments()[3]) create, _, err := req.Option("create").Bool() if err != nil { return "", err } var createfunc func() *dag.Node if create { createfunc = func() *dag.Node { return &dag.Node{Data: ft.FolderPBData()} } } e := dagutils.NewDagEditor(nd.DAG, root) childnd, err := nd.DAG.Get(req.Context(), childk) if err != nil { return "", err } err = e.InsertNodeAtPath(req.Context(), path, childnd, createfunc) if err != nil { return "", err } nnode := e.GetNode() return nnode.Key() }
func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) { if len(req.Arguments()) < 4 { return "", fmt.Errorf("not enough arguments for add-link") } nd, err := req.InvocContext().GetNode() if err != nil { return "", err } path := req.Arguments()[2] childk := key.B58KeyDecode(req.Arguments()[3]) parts := strings.Split(path, "/") nnode, err := insertNodeAtPath(req.Context(), nd.DAG, root, parts, childk) if err != nil { return "", err } return nnode.Key() }