Command line client for Write.as https://write.as/apps/cli
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

284 lines
7.0 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": "2.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 = "writeas"
  21. app.Version = appInfo["version"]
  22. app.Usage = "Publish text quickly"
  23. app.Authors = []cli.Author{
  24. {
  25. Name: "Write.as",
  26. Email: "hello@write.as",
  27. },
  28. }
  29. app.ExtraInfo = func() map[string]string {
  30. return appInfo
  31. }
  32. app.Action = commands.CmdPost
  33. app.Flags = append(config.PostFlags, flags...)
  34. app.Commands = []cli.Command{
  35. {
  36. Name: "post",
  37. Usage: "Alias for default action: create post from stdin",
  38. Action: commands.CmdPost,
  39. Flags: config.PostFlags,
  40. Description: `Create a new post on Write.as from stdin.
  41. Use the --code flag to indicate that the post should use syntax
  42. highlighting. Or use the --font [value] argument to set the post's
  43. appearance, where [value] is mono, monospace (default), wrap (monospace
  44. font with word wrapping), serif, or sans.`,
  45. },
  46. {
  47. Name: "new",
  48. Usage: "Compose a new post from the command-line and publish",
  49. Description: `An alternative to piping data to the program.
  50. On Windows, this will use 'copy con' to start reading what you input from the
  51. prompt. Press F6 or Ctrl-Z then Enter to end input.
  52. On *nix, this will use the best available text editor, starting with the
  53. value set to the WRITEAS_EDITOR or EDITOR environment variable, or vim, or
  54. finally nano.
  55. Use the --code flag to indicate that the post should use syntax
  56. highlighting. Or use the --font [value] argument to set the post's
  57. appearance, where [value] is mono, monospace (default), wrap (monospace
  58. font with word wrapping), serif, or sans.
  59. If posting fails for any reason, 'writeas' will show you the temporary file
  60. location and how to pipe it to 'writeas' to retry.`,
  61. Action: commands.CmdNew,
  62. Flags: config.PostFlags,
  63. },
  64. {
  65. Name: "publish",
  66. Usage: "Publish a file to Write.as",
  67. Action: commands.CmdPublish,
  68. Flags: config.PostFlags,
  69. },
  70. {
  71. Name: "delete",
  72. Usage: "Delete a post",
  73. Action: commands.CmdDelete,
  74. Flags: []cli.Flag{
  75. cli.BoolFlag{
  76. Name: "tor, t",
  77. Usage: "Delete via Tor hidden service",
  78. },
  79. cli.IntFlag{
  80. Name: "tor-port",
  81. Usage: "Use a different port to connect to Tor",
  82. Value: 9150,
  83. },
  84. cli.BoolFlag{
  85. Name: "verbose, v",
  86. Usage: "Make the operation more talkative",
  87. },
  88. },
  89. },
  90. {
  91. Name: "update",
  92. Usage: "Update (overwrite) a post",
  93. Action: commands.CmdUpdate,
  94. Flags: []cli.Flag{
  95. cli.BoolFlag{
  96. Name: "tor, t",
  97. Usage: "Update via Tor hidden service",
  98. },
  99. cli.IntFlag{
  100. Name: "tor-port",
  101. Usage: "Use a different port to connect to Tor",
  102. Value: 9150,
  103. },
  104. cli.BoolFlag{
  105. Name: "code",
  106. Usage: "Specifies this post is code",
  107. },
  108. cli.StringFlag{
  109. Name: "font",
  110. Usage: "Sets post font to given value",
  111. },
  112. cli.BoolFlag{
  113. Name: "verbose, v",
  114. Usage: "Make the operation more talkative",
  115. },
  116. },
  117. },
  118. {
  119. Name: "get",
  120. Usage: "Read a raw post",
  121. Action: commands.CmdGet,
  122. Flags: []cli.Flag{
  123. cli.BoolFlag{
  124. Name: "tor, t",
  125. Usage: "Get from Tor hidden service",
  126. },
  127. cli.IntFlag{
  128. Name: "tor-port",
  129. Usage: "Use a different port to connect to Tor",
  130. Value: 9150,
  131. },
  132. cli.BoolFlag{
  133. Name: "verbose, v",
  134. Usage: "Make the operation more talkative",
  135. },
  136. },
  137. },
  138. {
  139. Name: "add",
  140. Usage: "Add an existing post locally",
  141. Description: `A way to add an existing post to your local store for easy editing later.
  142. This requires a post ID (from https://write.as/[ID]) and an Edit Token
  143. (exported from another Write.as client, such as the Android app).
  144. `,
  145. Action: commands.CmdAdd,
  146. },
  147. {
  148. Name: "posts",
  149. Usage: "List all of your posts",
  150. Description: "This will list only local posts.",
  151. Action: commands.CmdListPosts,
  152. Flags: []cli.Flag{
  153. cli.BoolFlag{
  154. Name: "id",
  155. Usage: "Show list with post IDs (default)",
  156. },
  157. cli.BoolFlag{
  158. Name: "md",
  159. Usage: "Use with --url to return URLs with Markdown enabled",
  160. },
  161. cli.BoolFlag{
  162. Name: "tor, t",
  163. Usage: "Get posts via Tor hidden service, if authenticated",
  164. },
  165. cli.BoolFlag{
  166. Name: "url",
  167. Usage: "Show list with URLs",
  168. },
  169. cli.BoolFlag{
  170. Name: "verbose, v",
  171. Usage: "Show verbose post listing, including Edit Tokens",
  172. },
  173. },
  174. }, {
  175. Name: "blogs",
  176. Usage: "List blogs",
  177. Action: commands.CmdCollections,
  178. Flags: []cli.Flag{
  179. cli.BoolFlag{
  180. Name: "tor, t",
  181. Usage: "Authenticate via Tor hidden service",
  182. },
  183. cli.IntFlag{
  184. Name: "tor-port",
  185. Usage: "Use a different port to connect to Tor",
  186. Value: 9150,
  187. },
  188. cli.BoolFlag{
  189. Name: "url",
  190. Usage: "Show list with URLs",
  191. },
  192. },
  193. }, {
  194. Name: "claim",
  195. Usage: "Claim local unsynced posts",
  196. Action: commands.CmdClaim,
  197. Description: "This will claim any unsynced posts local to this machine. To see which posts these are run: writeas posts.",
  198. Flags: []cli.Flag{
  199. cli.BoolFlag{
  200. Name: "tor, t",
  201. Usage: "Authenticate via Tor hidden service",
  202. },
  203. cli.IntFlag{
  204. Name: "tor-port",
  205. Usage: "Use a different port to connect to Tor",
  206. Value: 9150,
  207. },
  208. cli.BoolFlag{
  209. Name: "verbose, v",
  210. Usage: "Make the operation more talkative",
  211. },
  212. },
  213. },
  214. {
  215. Name: "auth",
  216. Usage: "Authenticate with Write.as",
  217. Action: commands.CmdAuth,
  218. Flags: []cli.Flag{
  219. cli.BoolFlag{
  220. Name: "tor, t",
  221. Usage: "Authenticate via Tor hidden service",
  222. },
  223. cli.IntFlag{
  224. Name: "tor-port",
  225. Usage: "Use a different port to connect to Tor",
  226. Value: 9150,
  227. },
  228. cli.BoolFlag{
  229. Name: "verbose, v",
  230. Usage: "Make the operation more talkative",
  231. },
  232. cli.StringFlag{
  233. Name: "password, p",
  234. Usage: "The password for the account being logged into",
  235. },
  236. },
  237. },
  238. {
  239. Name: "logout",
  240. Usage: "Log out of Write.as",
  241. Action: commands.CmdLogOut,
  242. Flags: []cli.Flag{
  243. cli.BoolFlag{
  244. Name: "tor, t",
  245. Usage: "Authenticate via Tor hidden service",
  246. },
  247. cli.IntFlag{
  248. Name: "tor-port",
  249. Usage: "Use a different port to connect to Tor",
  250. Value: 9150,
  251. },
  252. cli.BoolFlag{
  253. Name: "verbose, v",
  254. Usage: "Make the operation more talkative",
  255. },
  256. },
  257. },
  258. }
  259. cli.CommandHelpTemplate = `NAME:
  260. {{.Name}} - {{.Usage}}
  261. USAGE:
  262. writeas {{.Name}}{{if .Flags}} [command options]{{end}} [arguments...]{{if .Description}}
  263. DESCRIPTION:
  264. {{.Description}}{{end}}{{if .Flags}}
  265. OPTIONS:
  266. {{range .Flags}}{{.}}
  267. {{end}}{{ end }}
  268. `
  269. app.Run(os.Args)
  270. }