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) }