Command line client for Write.as https://write.as/apps/cli
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

251 righe
6.2 KiB

  1. package main
  2. import (
  3. "os"
  4. "github.com/writeas/writeas-cli/commands"
  5. "github.com/writeas/writeas-cli/config"
  6. cli "gopkg.in/urfave/cli.v1"
  7. )
  8. func main() {
  9. appInfo := map[string]string{
  10. "configDir": configDir,
  11. "version": "1.0",
  12. }
  13. config.DirMustExist(config.UserDataDir(appInfo["configDir"]))
  14. cli.VersionFlag = cli.BoolFlag{
  15. Name: "version, V",
  16. Usage: "print the version",
  17. }
  18. // Run the app
  19. app := cli.NewApp()
  20. app.Name = "wf"
  21. app.Version = appInfo["version"]
  22. app.Usage = "Publish to any WriteFreely instance from the command-line."
  23. // TODO: who is the author? the contributors? link to GH?
  24. app.Authors = []cli.Author{
  25. {
  26. Name: "Write.as",
  27. Email: "hello@write.as",
  28. },
  29. }
  30. app.ExtraInfo = func() map[string]string {
  31. return appInfo
  32. }
  33. app.Action = requireAuth(commands.CmdPost, "publish")
  34. app.Flags = append(config.PostFlags, flags...)
  35. app.Commands = []cli.Command{
  36. {
  37. Name: "post",
  38. Usage: "Alias for default action: create post from stdin",
  39. Action: requireAuth(commands.CmdPost, "publish"),
  40. Flags: config.PostFlags,
  41. Description: `Create a new post on WriteFreely from stdin.
  42. Use the --code flag to indicate that the post should use syntax
  43. highlighting. Or use the --font [value] argument to set the post's
  44. appearance, where [value] is mono, monospace (default), wrap (monospace
  45. font with word wrapping), serif, or sans.`,
  46. },
  47. {
  48. Name: "new",
  49. Usage: "Compose a new post from the command-line and publish",
  50. Description: `An alternative to piping data to the program.
  51. On Windows, this will use 'copy con' to start reading what you input from the
  52. prompt. Press F6 or Ctrl-Z then Enter to end input.
  53. On *nix, this will use the best available text editor, starting with the
  54. value set to the WRITEAS_EDITOR or EDITOR environment variable, or vim, or
  55. finally nano.
  56. Use the --code flag to indicate that the post should use syntax
  57. highlighting. Or use the --font [value] argument to set the post's
  58. appearance, where [value] is mono, monospace (default), wrap (monospace
  59. font with word wrapping), serif, or sans.
  60. If posting fails for any reason, 'wf' will show you the temporary file
  61. location and how to pipe it to 'wf' to retry.`,
  62. Action: requireAuth(commands.CmdNew, "publish"),
  63. Flags: config.PostFlags,
  64. },
  65. {
  66. Name: "publish",
  67. Usage: "Publish a file",
  68. Action: requireAuth(commands.CmdPublish, "publish"),
  69. Flags: config.PostFlags,
  70. },
  71. {
  72. Name: "delete",
  73. Usage: "Delete a post",
  74. Action: requireAuth(commands.CmdDelete, "delete a post"),
  75. Flags: []cli.Flag{
  76. cli.BoolFlag{
  77. Name: "tor, t",
  78. Usage: "Delete via Tor hidden service",
  79. },
  80. cli.IntFlag{
  81. Name: "tor-port",
  82. Usage: "Use a different port to connect to Tor",
  83. Value: 9150,
  84. },
  85. cli.BoolFlag{
  86. Name: "verbose, v",
  87. Usage: "Make the operation more talkative",
  88. },
  89. },
  90. },
  91. {
  92. Name: "update",
  93. Usage: "Update (overwrite) a post",
  94. Action: requireAuth(commands.CmdUpdate, "update a post"),
  95. Flags: []cli.Flag{
  96. cli.BoolFlag{
  97. Name: "tor, t",
  98. Usage: "Update via Tor hidden service",
  99. },
  100. cli.IntFlag{
  101. Name: "tor-port",
  102. Usage: "Use a different port to connect to Tor",
  103. Value: 9150,
  104. },
  105. cli.BoolFlag{
  106. Name: "code",
  107. Usage: "Specifies this post is code",
  108. },
  109. cli.StringFlag{
  110. Name: "font",
  111. Usage: "Sets post font to given value",
  112. },
  113. cli.BoolFlag{
  114. Name: "verbose, v",
  115. Usage: "Make the operation more talkative",
  116. },
  117. },
  118. },
  119. {
  120. Name: "get",
  121. Usage: "Read a raw post",
  122. Action: commands.CmdGet,
  123. Flags: []cli.Flag{
  124. cli.BoolFlag{
  125. Name: "tor, t",
  126. Usage: "Get from Tor hidden service",
  127. },
  128. cli.IntFlag{
  129. Name: "tor-port",
  130. Usage: "Use a different port to connect to Tor",
  131. Value: 9150,
  132. },
  133. cli.BoolFlag{
  134. Name: "verbose, v",
  135. Usage: "Make the operation more talkative",
  136. },
  137. },
  138. },
  139. {
  140. Name: "posts",
  141. Usage: "List draft posts",
  142. Action: requireAuth(commands.CmdListPosts, "view posts"),
  143. Flags: []cli.Flag{
  144. cli.BoolFlag{
  145. Name: "id",
  146. Usage: "Show list with post IDs (default)",
  147. },
  148. cli.BoolFlag{
  149. Name: "url",
  150. Usage: "Show list with URLs",
  151. },
  152. cli.BoolFlag{
  153. Name: "verbose, v",
  154. Usage: "Show verbose post listing",
  155. },
  156. },
  157. }, {
  158. Name: "blogs",
  159. Usage: "List blogs",
  160. Action: requireAuth(commands.CmdCollections, "view blogs"),
  161. Flags: []cli.Flag{
  162. cli.BoolFlag{
  163. Name: "tor, t",
  164. Usage: "Authenticate via Tor hidden service",
  165. },
  166. cli.IntFlag{
  167. Name: "tor-port",
  168. Usage: "Use a different port to connect to Tor",
  169. Value: 9150,
  170. },
  171. cli.BoolFlag{
  172. Name: "url",
  173. Usage: "Show list with URLs",
  174. },
  175. },
  176. }, {
  177. Name: "accounts",
  178. Usage: "List all currently logged in accounts",
  179. Action: cmdAccounts,
  180. Flags: []cli.Flag{
  181. cli.BoolFlag{
  182. Name: "verbose, v",
  183. Usage: "Make the operation more talkative",
  184. },
  185. },
  186. }, {
  187. Name: "auth",
  188. Usage: "Authenticate with a WriteFreely instance",
  189. Action: cmdAuth,
  190. Flags: []cli.Flag{
  191. cli.BoolFlag{
  192. Name: "tor, t",
  193. Usage: "Authenticate via Tor hidden service",
  194. },
  195. cli.IntFlag{
  196. Name: "tor-port",
  197. Usage: "Use a different port to connect to Tor",
  198. Value: 9150,
  199. },
  200. cli.BoolFlag{
  201. Name: "verbose, v",
  202. Usage: "Make the operation more talkative",
  203. },
  204. },
  205. },
  206. {
  207. Name: "logout",
  208. Usage: "Log out of a WriteFreely instance",
  209. Action: requireAuth(cmdLogOut, "logout"),
  210. Flags: []cli.Flag{
  211. cli.BoolFlag{
  212. Name: "tor, t",
  213. Usage: "Authenticate via Tor hidden service",
  214. },
  215. cli.IntFlag{
  216. Name: "tor-port",
  217. Usage: "Use a different port to connect to Tor",
  218. Value: 9150,
  219. },
  220. cli.BoolFlag{
  221. Name: "verbose, v",
  222. Usage: "Make the operation more talkative",
  223. },
  224. },
  225. },
  226. }
  227. cli.CommandHelpTemplate = `NAME:
  228. {{.Name}} - {{.Usage}}
  229. USAGE:
  230. wf {{.Name}}{{if .Flags}} [command options]{{end}} [arguments...]{{if .Description}}
  231. DESCRIPTION:
  232. {{.Description}}{{end}}{{if .Flags}}
  233. OPTIONS:
  234. {{range .Flags}}{{.}}
  235. {{end}}{{ end }}
  236. `
  237. app.Run(os.Args)
  238. }