diff --git a/writeas/commands.go b/writeas/commands.go index cd9ff60..68c5b68 100644 --- a/writeas/commands.go +++ b/writeas/commands.go @@ -1,157 +1,157 @@ package main import ( "fmt" "github.com/codegangsta/cli" "os" ) func cmdPost(c *cli.Context) { err := handlePost(readStdIn(), c) check(err) } func cmdNew(c *cli.Context) { fname, p := composeNewPost() if p == nil { // Assume composeNewPost already told us what the error was. Abort now. os.Exit(1) } // Ensure we have something to post if len(*p) == 0 { // Clean up temporary post if fname != "" { os.Remove(fname) } fmt.Println("Empty post. Bye!") os.Exit(0) } err := handlePost(*p, c) if err != nil { fmt.Fprintf(os.Stderr, "Error posting: %s\n", err) fmt.Println(messageRetryCompose(fname)) os.Exit(1) } // Clean up temporary post if fname != "" { os.Remove(fname) } } func cmdDelete(c *cli.Context) { - friendlyId := c.Args().Get(0) + friendlyID := c.Args().Get(0) token := c.Args().Get(1) - if friendlyId == "" { + if friendlyID == "" { fmt.Println("usage: writeas delete []") os.Exit(1) } if token == "" { // Search for the token locally - token = tokenFromID(friendlyId) + token = tokenFromID(friendlyID) if token == "" { fmt.Println("Couldn't find an edit token locally. Did you create this post here?") - fmt.Printf("If you have an edit token, use: writeas delete %s \n", friendlyId) + fmt.Printf("If you have an edit token, use: writeas delete %s \n", friendlyID) os.Exit(1) } } tor := c.Bool("tor") || c.Bool("t") if c.Int("tor-port") != 0 { torPort = c.Int("tor-port") } if tor { fmt.Println("Deleting via hidden service...") } else { fmt.Println("Deleting...") } - DoDelete(friendlyId, token, tor) + DoDelete(friendlyID, token, tor) } func cmdUpdate(c *cli.Context) { - friendlyId := c.Args().Get(0) + friendlyID := c.Args().Get(0) token := c.Args().Get(1) - if friendlyId == "" { + if friendlyID == "" { fmt.Println("usage: writeas update []") os.Exit(1) } if token == "" { // Search for the token locally - token = tokenFromID(friendlyId) + token = tokenFromID(friendlyID) if token == "" { fmt.Println("Couldn't find an edit token locally. Did you create this post here?") - fmt.Printf("If you have an edit token, use: writeas update %s \n", friendlyId) + fmt.Printf("If you have an edit token, use: writeas update %s \n", friendlyID) os.Exit(1) } } // Read post body fullPost := readStdIn() tor := c.Bool("tor") || c.Bool("t") if c.Int("tor-port") != 0 { torPort = c.Int("tor-port") } if tor { fmt.Println("Updating via hidden service...") } else { fmt.Println("Updating...") } - DoUpdate(fullPost, friendlyId, token, c.String("font"), tor, c.Bool("code")) + DoUpdate(fullPost, friendlyID, token, c.String("font"), tor, c.Bool("code")) } func cmdGet(c *cli.Context) { - friendlyId := c.Args().Get(0) - if friendlyId == "" { + friendlyID := c.Args().Get(0) + if friendlyID == "" { fmt.Println("usage: writeas get ") os.Exit(1) } tor := c.Bool("tor") || c.Bool("t") if c.Int("tor-port") != 0 { torPort = c.Int("tor-port") } if tor { fmt.Println("Getting via hidden service...") } else { fmt.Println("Getting...") } - DoFetch(friendlyId, tor) + DoFetch(friendlyID, tor) } func cmdAdd(c *cli.Context) { - friendlyId := c.Args().Get(0) + friendlyID := c.Args().Get(0) token := c.Args().Get(1) - if friendlyId == "" || token == "" { + if friendlyID == "" || token == "" { fmt.Println("usage: writeas add ") os.Exit(1) } - addPost(friendlyId, token) + addPost(friendlyID, token) } func cmdList(c *cli.Context) { urls := c.Bool("url") ids := c.Bool("id") var p Post posts := getPosts() for i := range *posts { p = (*posts)[len(*posts)-1-i] if ids || !urls { fmt.Printf("%s ", p.ID) } if urls { fmt.Printf("https://write.as/%s ", p.ID) } fmt.Print("\n") } }