Get markdown command

This commit is contained in:
Toby Padilla 2020-04-23 17:55:51 -05:00 committed by Christian Muehlhaeuser
parent 395ae998dd
commit bd52d1cee4
2 changed files with 23 additions and 0 deletions

View file

@ -258,4 +258,5 @@ func init() {
rootCmd.AddCommand(stashCmd)
rootCmd.AddCommand(stashListCmd)
rootCmd.AddCommand(stashGetCmd)
}

View file

@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"os"
"strconv"
"github.com/charmbracelet/charm"
"github.com/spf13/cobra"
@ -60,6 +61,27 @@ var (
return nil
},
}
stashGetCmd = &cobra.Command{
Use: "stash-get",
Hidden: false,
Short: "get a stashed markdown by id",
Long: "",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
id, err := strconv.Atoi(args[0])
if err != nil {
return fmt.Errorf("invalid markdown id")
}
cc := initCharmClient()
md, err := cc.GetMarkdown(id)
if err != nil {
return fmt.Errorf("error getting markdown")
}
fmt.Println(md.Body)
return nil
},
}
)
func getCharmConfig() *charm.Config {