PageRenderTime 88ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/gitsome/completions.py

https://gitlab.com/vectorci/gitsome
Python | 330 lines | 311 code | 6 blank | 13 comment | 3 complexity | 157524f362f962ee76652137e7ee846a MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Donne Martin. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"). You
  5. # may not use this file except in compliance with the License. A copy of
  6. # the License is located at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # or in the "license" file accompanying this file. This file is
  11. # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  12. # ANY KIND, either express or implied. See the License for the specific
  13. # language governing permissions and limitations under the License.
  14. COMPLETIONS_GH = {
  15. 'configure': {
  16. 'desc': "Configures gitsome.",
  17. 'args': {},
  18. 'opts': {
  19. '-e': 'flag (opt) configure GitHub Enterprise.',
  20. '--enterprise': 'flag (opt) configure GitHub Enterprise.',
  21. },
  22. },
  23. 'create-comment': {
  24. 'desc': 'Creates a comment on the given issue.',
  25. 'args': {
  26. 'octocat/Spoon-Knife/1': 'str (req) user/repo/issue_number combo.',
  27. },
  28. 'opts': {
  29. '-t': 'see associated -- option for details.',
  30. '--text': 'str (req) comment text.',
  31. },
  32. },
  33. 'create-issue': {
  34. 'desc': 'Creates an issue.',
  35. 'args': {
  36. 'octocat/Spoon-Knife': 'str (req) user/repository combo.',
  37. },
  38. 'opts': {
  39. '-t': 'see associated -- option for details.',
  40. '--issue_title': 'str (req) issue title.',
  41. '-d': 'str (opt) issue description.',
  42. '--issue_desc': 'str (opt) issue description.',
  43. },
  44. },
  45. 'create-repo': {
  46. 'desc': 'Creates a repository.',
  47. 'args': {
  48. 'Spoon-Knife': 'str (req) repository name.',
  49. },
  50. 'opts': {
  51. '-d': 'str (opt) repo description',
  52. '--repo_desc': 'str (opt) repo description.',
  53. '-pr': 'flag (opt) create a private repo',
  54. '--private': 'flag (opt) create a private repo',
  55. },
  56. },
  57. 'emails': {
  58. 'desc': "Lists all the user's registered emails.",
  59. 'args': {},
  60. 'opts': {},
  61. },
  62. 'emojis': {
  63. 'desc': 'Lists all GitHub supported emojis.',
  64. 'args': {},
  65. 'opts': {
  66. '-p': 'flag (req) show results in a pager.',
  67. '--pager': 'flag (req) show results in a pager.',
  68. },
  69. },
  70. 'feed': {
  71. 'desc': "Lists all activity for the given user or repo, if called with no arg, shows the logged in user's feed.",
  72. 'args': {
  73. 'octocat/Hello-World --pager': "str (opt) user or user/repository combo, if blank, shows the logged in user's feed.",
  74. },
  75. 'opts': {
  76. '-pr': 'flag (req) also show private events.',
  77. '--private': 'flag (req) also show private events.',
  78. '-p': 'flag (req) show results in a pager.',
  79. '--pager': 'flag (req) show results in a pager.',
  80. },
  81. },
  82. 'followers': {
  83. 'desc': 'Lists all followers and the total follower count.',
  84. 'args': {
  85. 'octocat': "str (req) the user's login id, if blank, shows logged in user's info.",
  86. },
  87. 'opts': {
  88. '-p': 'flag (opt) show results in a pager.',
  89. '--pager': 'flag (opt) show results in a pager.',
  90. },
  91. },
  92. 'following': {
  93. 'desc': 'Lists all followed users and the total followed count.',
  94. 'args': {
  95. 'octocat': "str (req) the user's login id, if blank, shows logged in user's info.",
  96. },
  97. 'opts': {
  98. '-p': 'flag (opt) show results in a pager.',
  99. '--pager': 'flag (opt) show results in a pager.',
  100. },
  101. },
  102. 'gitignore-template': {
  103. 'desc': 'Outputs the gitignore template for the given language.',
  104. 'args': {
  105. 'Python': 'str (req) the language-specific .gitignore.',
  106. },
  107. 'opts': {},
  108. },
  109. 'gitignore-templates': {
  110. 'desc': 'Outputs all supported gitignore templates.',
  111. 'args': {},
  112. 'opts': {
  113. '-p': 'flag (opt) show results in a pager.',
  114. '--pager': 'flag (opt) show results in a pager.',
  115. },
  116. },
  117. 'issue': {
  118. 'desc': 'Outputs detailed information about the given issue.',
  119. 'args': {
  120. 'octocat/Spoon-Knife/1': 'str (req) user/repo/issue_number combo.',
  121. },
  122. 'opts': {},
  123. },
  124. 'issues': {
  125. 'desc': 'Lists all issues matching the filter.',
  126. 'args': {},
  127. 'opts': {
  128. '-f': 'str (opt) "assigned", "created", "mentioned", "subscribed" (default).',
  129. '--issue_filter': 'str (opt) "assigned", "created", "mentioned", "subscribed" (default).',
  130. '-s': 'str (opt) "all", "open" (default), "closed".',
  131. '--issue_state': 'str (opt) "all", "open" (default), "closed".',
  132. '-l': 'flag (opt) num items to show, defaults to 1000.',
  133. '--limit': 'flag (opt) num items to show, defaults to 1000.',
  134. '-p': 'flag (opt) show results in a pager.',
  135. '--pager': 'flag (opt) show results in a pager.',
  136. },
  137. },
  138. 'license': {
  139. 'desc': 'Outputs the license template for the given license.',
  140. 'args': {
  141. 'apache-2.0': 'str (req) the license name.',
  142. },
  143. 'opts': {},
  144. },
  145. 'licenses': {
  146. 'desc': 'Outputs all supported license templates.',
  147. 'args': {},
  148. 'opts': {},
  149. },
  150. 'me': {
  151. 'desc': 'Lists information about the logged in user.',
  152. 'args': {},
  153. 'opts': {
  154. '-b': 'flag (opt) view profile in a browser instead of the terminal.',
  155. '--browser': 'flag (opt) view profile in a browser instead of the terminal.',
  156. '-t': 'see associated -- option for details.',
  157. '--text_avatar': 'flag (opt) view profile pic in plain text.',
  158. '-l': 'flag (opt) num items to show, defaults to 1000.',
  159. '--limit': 'flag (opt) num items to show, defaults to 1000.',
  160. '-p': 'flag (opt) show results in a pager.',
  161. '--pager': 'flag (opt) show results in a pager.',
  162. },
  163. },
  164. 'notifications': {
  165. 'desc': 'Lists all notifications.',
  166. 'args': {},
  167. 'opts': {
  168. '-l': 'flag (opt) num items to show, defaults to 1000.',
  169. '--limit': 'flag (opt) num items to show, defaults to 1000.',
  170. '-p': 'flag (opt) show results in a pager.',
  171. '--pager': 'flag (opt) show results in a pager.',
  172. },
  173. },
  174. 'octo': {
  175. 'desc': 'Outputs an Easter egg or the given message from Octocat.',
  176. 'args': {
  177. '"Keep it logically awesome"': 'str (req) a message from Octocat, if empty, Octocat speaks an Easter egg.',
  178. },
  179. 'opts': {},
  180. },
  181. 'pull-request': {
  182. 'desc': 'Outputs detailed information about the given pull request.',
  183. 'args': {
  184. 'octocat/Spoon-Knife/3': 'str (req) user/repo/pull_number combo.',
  185. },
  186. 'opts': {},
  187. },
  188. 'pull-requests': {
  189. 'desc': 'Lists all pull requests.',
  190. 'args': {},
  191. 'opts': {
  192. '-l': 'flag (opt) num items to show, defaults to 1000.',
  193. '--limit': 'flag (opt) num items to show, defaults to 1000.',
  194. '-p': 'flag (opt) show results in a pager.',
  195. '--pager': 'flag (opt) show results in a pager.',
  196. },
  197. },
  198. 'rate-limit': {
  199. 'desc': 'Outputs the rate limit.',
  200. 'args': {},
  201. 'opts': {},
  202. },
  203. 'repo': {
  204. 'desc': 'Outputs detailed information about the given repo.',
  205. 'args': {
  206. 'octocat/Spoon-Knife': 'str (req) user/repository combo.',
  207. },
  208. 'opts': {},
  209. },
  210. 'repos': {
  211. 'desc': 'Lists all repos matching the given filter.',
  212. 'args': {
  213. '"foo bar optional filter"': 'str (opt) filters repos by name.',
  214. },
  215. 'opts': {
  216. '-l': 'flag (opt) num items to show, defaults to 1000.',
  217. '--limit': 'flag (opt) num items to show, defaults to 1000.',
  218. '-p': 'flag (opt) show results in a pager.',
  219. '--pager': 'flag (opt) show results in a pager.',
  220. },
  221. },
  222. 'search-issues': {
  223. 'desc': 'Searches for all issues matching the given query.',
  224. 'args': {
  225. '"foobarbaz in:title created:>=2015-01-01"': 'str (req) the search query.',
  226. },
  227. 'opts': {
  228. '-s': 'str (opt) "stars", "forks", "updated", if blank, sorts by query best match.',
  229. '--sort': 'str (opt) "stars", "forks", "updated", if blank, sorts by query best match.',
  230. '-l': 'flag (opt) num items to show, defaults to 1000.',
  231. '--limit': 'flag (opt) num items to show, defaults to 1000.',
  232. '-p': 'flag (opt) show results in a pager.',
  233. '--pager': 'flag (opt) show results in a pager.',
  234. },
  235. },
  236. 'search-repos': {
  237. 'desc': 'Searches for all repos matching the given query.',
  238. 'args': {
  239. '"created:>=2015-01-01 stars:>=1500 language:python"': 'str (req) the search query.',
  240. },
  241. 'opts': {
  242. '-s': 'str (opt) "stars", "forks", "updated", if blank, sorts by query best match.',
  243. '--sort': 'str (opt) "stars", "forks", "updated", if blank, sorts by query best match.',
  244. '-l': 'flag (opt) num items to show, defaults to 1000.',
  245. '--limit': 'flag (opt) num items to show, defaults to 1000.',
  246. '-p': 'flag (opt) show results in a pager.',
  247. '--pager': 'flag (opt) show results in a pager.',
  248. },
  249. },
  250. 'starred': {
  251. 'desc': 'Outputs starred repos.',
  252. 'args': {
  253. '"foo bar optional filter"': 'str (opt) filters repos by name.',
  254. },
  255. 'opts': {
  256. '-l': 'flag (opt) num items to show, defaults to 1000.',
  257. '--limit': 'flag (opt) num items to show, defaults to 1000.',
  258. '-p': 'flag (opt) show results in a pager.',
  259. '--pager': 'flag (opt) show results in a pager.',
  260. },
  261. },
  262. 'trending': {
  263. 'desc': 'Lists trending repos for the given language.',
  264. 'args': {
  265. 'Overall': 'str (opt) the language filter for trending repos, if blank, the overall rankings are shown.',
  266. },
  267. 'opts': {
  268. '-w': 'flag (opt) show the weekly trending repos.',
  269. '--weekly': 'flag (opt) show the weekly trending repos.',
  270. '-m': 'flag (opt) show the monthly trending repos.',
  271. '--monthly': 'flag (opt) show the monthly trending repos.',
  272. '-D': 'flag (opt) view trending devs. Only valid with -b/--browser.',
  273. '--devs': 'flag (opt) view trending devs. Only valid with -b/--browser.',
  274. '-b': 'flag (opt) view profile in a browser instead of the terminal.',
  275. '--browser': 'flag (opt) view profile in a browser instead of the terminal.',
  276. '-p': 'flag (opt) show results in a pager.',
  277. '--pager': 'flag (opt) show results in a pager.',
  278. },
  279. },
  280. 'user': {
  281. 'desc': 'Lists information about the given user.',
  282. 'args': {
  283. 'github --pager': "str (req) the user's login id.",
  284. },
  285. 'opts': {
  286. '-b': 'flag (opt) view profile in a browser instead of the terminal.',
  287. '--browser': 'flag (opt) view profile in a browser instead of the terminal.',
  288. '-t': 'see associated -- option for details.',
  289. '--text_avatar': 'flag (opt) view profile pic in plain text.',
  290. '-l': 'flag (opt) num items to show, defaults to 1000.',
  291. '--limit': 'flag (opt) num items to show, defaults to 1000.',
  292. '-p': 'flag (opt) show results in a pager.',
  293. '--pager': 'flag (opt) show results in a pager.',
  294. },
  295. },
  296. 'view': {
  297. 'desc': 'Views the given repo or issue index in the terminal or a browser.',
  298. 'args': {
  299. '1': 'int (req) the 1-based index to view.',
  300. },
  301. 'opts': {
  302. '-b': 'flag (opt) view profile in a browser instead of the terminal.',
  303. '--browser': 'flag (opt) view profile in a browser instead of the terminal.',
  304. },
  305. },
  306. }
  307. META_LOOKUP_GH = {
  308. '10': 'limit: int (opt) limits the posts displayed',
  309. '"(?i)(Python|Django)"': ('regex_query: string (opt) applies a regular '
  310. 'expression comment filter'),
  311. '1': 'index: int (req) views the post index',
  312. '"user"': 'user:string (req) shows info on the specified user',
  313. 'gh': 'Git auto-completer with GitHub integration.',
  314. }
  315. SUBCOMMANDS = {}
  316. def build_meta_lookups():
  317. for subcommand, args_opts in COMPLETIONS_GH.items():
  318. META_LOOKUP_GH.update({subcommand: COMPLETIONS_GH[subcommand]['desc']})
  319. SUBCOMMANDS.update({subcommand: COMPLETIONS_GH[subcommand]['desc']})
  320. for opt, meta in args_opts['opts'].items():
  321. META_LOOKUP_GH.update({opt: meta})
  322. for arg, meta in args_opts['args'].items():
  323. META_LOOKUP_GH.update({arg: meta})
  324. build_meta_lookups()