Exemple #1
0
func cliListPosts(c *cli.Context) {
	topicId := c.String("topicId")
	showIds := c.Bool("ids")
	if topicId == "" {
		log.Fatal("You must specify a topic id")
	}
	client, err := client.NewDialogueClient(URL, USERNAME, TOKEN)
	if err != nil {
		log.Fatal(err)
	}
	posts, err := client.GetPosts(topicId)
	if err != nil {
		log.Fatal(err)
	}
	if len(posts) == 0 {
		return
	}
	w := getTableWriter()
	for _, p := range posts {
		fmt.Fprintf(w, "%v\t -%s", p.Content, p.Author)
		if showIds {
			fmt.Fprintf(w, "\t%s", p.Id)
		}
		fmt.Fprint(w, "\n")
	}
	w.Flush()
}
Exemple #2
0
func cliDeletePost(c *cli.Context) {
	id := c.String("id")
	if id == "" {
		log.Fatal("You must specify a post ID")
	}
	client, err := client.NewDialogueClient(URL, USERNAME, TOKEN)
	if err != nil {
		log.Fatal(err)
	}
	if err := client.DeletePost(id); err != nil {
		log.Fatal(err)
	}
}
Exemple #3
0
func cliCreateTopic(c *cli.Context) {
	title := c.String("title")
	if title == "" {
		log.Fatal("You must specify a title")
	}
	client, err := client.NewDialogueClient(URL, USERNAME, TOKEN)
	if err != nil {
		log.Fatal(err)
	}
	if err := client.CreateTopic(title); err != nil {
		log.Fatal(err)
	}
}
Exemple #4
0
func cliCreatePost(c *cli.Context) {
	content := c.String("content")
	topicId := c.String("topicId")
	if content == "" || topicId == "" {
		log.Fatal("You must specify a topic id and content")
	}
	client, err := client.NewDialogueClient(URL, USERNAME, TOKEN)
	if err != nil {
		log.Fatal(err)
	}
	if err := client.CreatePost(topicId, content); err != nil {
		log.Fatal(err)
	}
}
Exemple #5
0
func cliListTopics(c *cli.Context) {
	client, err := client.NewDialogueClient(URL, USERNAME, TOKEN)
	if err != nil {
		log.Fatal(err)
	}
	topics, err := client.GetTopics()
	if err != nil {
		log.Fatal(err)
	}
	if len(topics) == 0 {
		return
	}
	w := getTableWriter()
	fmt.Fprint(w, "Title\tID\t\n")
	for _, t := range topics {
		fmt.Fprintf(w, "%s\t%v\t\n", t.Title, t.Id)
	}
	w.Flush()
}