Skip to content

Commit 14126b5

Browse files
committed
add stories and discussions command
1 parent 344a80c commit 14126b5

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

cmd/posts.go renamed to cmd/discussions.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,18 @@ import (
77

88
// flags
99
var (
10-
hot bool
11-
news bool
12-
trending bool
10+
hot bool
1311
)
1412

1513
// postsCmd represents the posts command
1614
var postsCmd = &cobra.Command{
17-
Use: "posts",
18-
Short: "Lists posts",
15+
Use: "dicussions",
16+
Short: "Read discussions on hashnode",
17+
Aliases: []string{"d"},
1918
Run: func(cmd *cobra.Command, args []string) {
2019
switch {
21-
case news:
22-
posts.GetNews()
2320
case hot:
2421
posts.GetHotPosts()
25-
case trending:
26-
posts.GetTrendingPosts()
2722
default:
2823
cmd.Help()
2924
}
@@ -34,6 +29,4 @@ func init() {
3429
rootCmd.AddCommand(postsCmd)
3530

3631
postsCmd.PersistentFlags().BoolVar(&hot, "hot", false, "get hot posts")
37-
postsCmd.PersistentFlags().BoolVar(&news, "news", false, "get news")
38-
postsCmd.PersistentFlags().BoolVar(&trending, "trending", false, "get trending stories")
3932
}

cmd/stories.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cmd
2+
3+
import (
4+
"github.com/hashnode/hashnode-cli/pkg/posts"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
//flags
9+
var (
10+
trending bool
11+
)
12+
13+
// storiesCmd represents the stories command
14+
var storiesCmd = &cobra.Command{
15+
Use: "stories",
16+
Short: "Read stories published on hashnode",
17+
Aliases: []string{"s"},
18+
Run: func(cmd *cobra.Command, args []string) {
19+
switch {
20+
case trending:
21+
posts.GetTrendingPosts()
22+
default:
23+
cmd.Help()
24+
}
25+
},
26+
}
27+
28+
func init() {
29+
rootCmd.AddCommand(storiesCmd)
30+
31+
storiesCmd.PersistentFlags().BoolVar(&trending, "hot", false, "get hot trending stories")
32+
}

0 commit comments

Comments
 (0)