Remove program from args to simplify command parsing
This commit is contained in:
parent
fa35d331ec
commit
845e2ce43e
|
@ -130,46 +130,46 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
performCommands(&c, os.Args)
|
performCommands(&c, os.Args[1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func performCommands(sub microsub.Microsub, commands []string) {
|
func performCommands(sub microsub.Microsub, commands []string) {
|
||||||
|
|
||||||
if len(commands) == 2 && commands[1] == "channels" {
|
if len(commands) == 1 && commands[0] == "channels" {
|
||||||
channels := sub.ChannelsGetList()
|
channels := sub.ChannelsGetList()
|
||||||
for _, ch := range channels {
|
for _, ch := range channels {
|
||||||
fmt.Println(ch.UID, " ", ch.Name)
|
fmt.Println(ch.UID, " ", ch.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commands) == 3 && commands[1] == "channels" {
|
if len(commands) == 2 && commands[0] == "channels" {
|
||||||
name := commands[2]
|
name := commands[1]
|
||||||
channel := sub.ChannelsCreate(name)
|
channel := sub.ChannelsCreate(name)
|
||||||
fmt.Printf("Channel created %s %s\n", channel.Name, channel.UID)
|
fmt.Printf("Channel created %s %s\n", channel.Name, channel.UID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commands) == 4 && commands[1] == "channels" {
|
if len(commands) == 3 && commands[0] == "channels" {
|
||||||
uid := commands[2]
|
uid := commands[1]
|
||||||
if uid == "-delete" {
|
if uid == "-delete" {
|
||||||
uid = commands[3]
|
uid = commands[2]
|
||||||
sub.ChannelsDelete(uid)
|
sub.ChannelsDelete(uid)
|
||||||
fmt.Println("Channel deleted")
|
fmt.Println("Channel deleted")
|
||||||
} else {
|
} else {
|
||||||
name := commands[3]
|
name := commands[2]
|
||||||
channel := sub.ChannelsUpdate(uid, name)
|
channel := sub.ChannelsUpdate(uid, name)
|
||||||
fmt.Printf("Channel updated %s %s\n", channel.Name, channel.UID)
|
fmt.Printf("Channel updated %s %s\n", channel.Name, channel.UID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commands) >= 3 && commands[1] == "timeline" {
|
if len(commands) >= 2 && commands[0] == "timeline" {
|
||||||
channel := commands[2]
|
channel := commands[1]
|
||||||
|
|
||||||
var timeline microsub.Timeline
|
var timeline microsub.Timeline
|
||||||
|
|
||||||
if len(commands) == 5 && commands[3] == "-after" {
|
if len(commands) == 4 && commands[2] == "-after" {
|
||||||
timeline = sub.TimelineGet("", commands[4], channel)
|
timeline = sub.TimelineGet("", commands[3], channel)
|
||||||
} else if len(commands) == 5 && commands[3] == "-before" {
|
} else if len(commands) == 4 && commands[2] == "-before" {
|
||||||
timeline = sub.TimelineGet(commands[4], "", channel)
|
timeline = sub.TimelineGet(commands[3], "", channel)
|
||||||
} else {
|
} else {
|
||||||
timeline = sub.TimelineGet("", "", channel)
|
timeline = sub.TimelineGet("", "", channel)
|
||||||
}
|
}
|
||||||
|
@ -181,8 +181,8 @@ func performCommands(sub microsub.Microsub, commands []string) {
|
||||||
fmt.Printf("Before: %s, After: %s\n", timeline.Paging.Before, timeline.Paging.After)
|
fmt.Printf("Before: %s, After: %s\n", timeline.Paging.Before, timeline.Paging.After)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commands) == 3 && commands[1] == "search" {
|
if len(commands) == 2 && commands[0] == "search" {
|
||||||
query := commands[2]
|
query := commands[1]
|
||||||
feeds := sub.Search(query)
|
feeds := sub.Search(query)
|
||||||
|
|
||||||
for _, feed := range feeds {
|
for _, feed := range feeds {
|
||||||
|
@ -190,8 +190,8 @@ func performCommands(sub microsub.Microsub, commands []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commands) == 3 && commands[1] == "preview" {
|
if len(commands) == 2 && commands[0] == "preview" {
|
||||||
url := commands[2]
|
url := commands[1]
|
||||||
timeline := sub.PreviewURL(url)
|
timeline := sub.PreviewURL(url)
|
||||||
|
|
||||||
for _, item := range timeline.Items {
|
for _, item := range timeline.Items {
|
||||||
|
@ -199,23 +199,23 @@ func performCommands(sub microsub.Microsub, commands []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commands) == 3 && commands[1] == "follow" {
|
if len(commands) == 2 && commands[0] == "follow" {
|
||||||
uid := commands[2]
|
uid := commands[1]
|
||||||
feeds := sub.FollowGetList(uid)
|
feeds := sub.FollowGetList(uid)
|
||||||
for _, feed := range feeds {
|
for _, feed := range feeds {
|
||||||
fmt.Println(feed.Name, " ", feed.URL)
|
fmt.Println(feed.Name, " ", feed.URL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commands) == 4 && commands[1] == "follow" {
|
if len(commands) == 3 && commands[0] == "follow" {
|
||||||
uid := commands[2]
|
uid := commands[1]
|
||||||
url := commands[3]
|
url := commands[2]
|
||||||
sub.FollowURL(uid, url)
|
sub.FollowURL(uid, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commands) == 4 && commands[1] == "unfollow" {
|
if len(commands) == 3 && commands[0] == "unfollow" {
|
||||||
uid := commands[2]
|
uid := commands[1]
|
||||||
url := commands[3]
|
url := commands[2]
|
||||||
sub.UnfollowURL(uid, url)
|
sub.UnfollowURL(uid, url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user