fluid_cli 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1 -0
  3. data/dev.yml +5 -0
  4. data/exe/fluid +24 -0
  5. data/lib/fluid_cli/api.rb +135 -0
  6. data/lib/fluid_cli/assets/post_auth_page/index.html.erb +34 -0
  7. data/lib/fluid_cli/assets/post_auth_page/style.css +58 -0
  8. data/lib/fluid_cli/command.rb +55 -0
  9. data/lib/fluid_cli/commands/help.rb +21 -0
  10. data/lib/fluid_cli/commands/login.rb +30 -0
  11. data/lib/fluid_cli/commands/logout.rb +38 -0
  12. data/lib/fluid_cli/commands/switch.rb +23 -0
  13. data/lib/fluid_cli/commands/theme/common/company_helper.rb +15 -0
  14. data/lib/fluid_cli/commands/theme/common/root_helper.rb +95 -0
  15. data/lib/fluid_cli/commands/theme/dev.rb +61 -0
  16. data/lib/fluid_cli/commands/theme/help.rb +21 -0
  17. data/lib/fluid_cli/commands/theme/init.rb +46 -0
  18. data/lib/fluid_cli/commands/theme/pull.rb +68 -0
  19. data/lib/fluid_cli/commands/theme/push.rb +132 -0
  20. data/lib/fluid_cli/commands/theme.rb +23 -0
  21. data/lib/fluid_cli/commands/whoami.rb +23 -0
  22. data/lib/fluid_cli/commands.rb +19 -0
  23. data/lib/fluid_cli/company_switcher.rb +69 -0
  24. data/lib/fluid_cli/context.rb +691 -0
  25. data/lib/fluid_cli/db.rb +114 -0
  26. data/lib/fluid_cli/entry_point.rb +10 -0
  27. data/lib/fluid_cli/environment.rb +32 -0
  28. data/lib/fluid_cli/file_system_listener.rb +29 -0
  29. data/lib/fluid_cli/form.rb +42 -0
  30. data/lib/fluid_cli/git.rb +319 -0
  31. data/lib/fluid_cli/http_request.rb +54 -0
  32. data/lib/fluid_cli/identity_auth/servlet.rb +39 -0
  33. data/lib/fluid_cli/identity_auth.rb +126 -0
  34. data/lib/fluid_cli/options.rb +38 -0
  35. data/lib/fluid_cli/theme/dev_server/certificate_manager.rb +79 -0
  36. data/lib/fluid_cli/theme/dev_server/errors.rb +9 -0
  37. data/lib/fluid_cli/theme/dev_server/header_hash.rb +98 -0
  38. data/lib/fluid_cli/theme/dev_server/hooks/file_change_hook.rb +39 -0
  39. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot-reload-no-script.html +27 -0
  40. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/hot_reload.js +28 -0
  41. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/sse_client.js +43 -0
  42. data/lib/fluid_cli/theme/dev_server/hot_reload/resources/theme.js +16 -0
  43. data/lib/fluid_cli/theme/dev_server/hot_reload/script_injector.rb +54 -0
  44. data/lib/fluid_cli/theme/dev_server/hot_reload.rb +75 -0
  45. data/lib/fluid_cli/theme/dev_server/local_assets.rb +92 -0
  46. data/lib/fluid_cli/theme/dev_server/proxy.rb +235 -0
  47. data/lib/fluid_cli/theme/dev_server/proxy_param_builder.rb +82 -0
  48. data/lib/fluid_cli/theme/dev_server/reload_mode.rb +34 -0
  49. data/lib/fluid_cli/theme/dev_server/sse.rb +75 -0
  50. data/lib/fluid_cli/theme/dev_server/watcher.rb +57 -0
  51. data/lib/fluid_cli/theme/dev_server/web_server.rb +140 -0
  52. data/lib/fluid_cli/theme/dev_server.rb +289 -0
  53. data/lib/fluid_cli/theme/development_theme.rb +101 -0
  54. data/lib/fluid_cli/theme/file.rb +105 -0
  55. data/lib/fluid_cli/theme/forms/select.rb +33 -0
  56. data/lib/fluid_cli/theme/mime_type.rb +34 -0
  57. data/lib/fluid_cli/theme/presenters/theme_presenter.rb +49 -0
  58. data/lib/fluid_cli/theme/presenters/themes_presenter.rb +31 -0
  59. data/lib/fluid_cli/theme/root.rb +62 -0
  60. data/lib/fluid_cli/theme/syncer/checksums.rb +66 -0
  61. data/lib/fluid_cli/theme/syncer/downloader.rb +54 -0
  62. data/lib/fluid_cli/theme/syncer/error_reporter.rb +45 -0
  63. data/lib/fluid_cli/theme/syncer/merger.rb +53 -0
  64. data/lib/fluid_cli/theme/syncer/operation.rb +58 -0
  65. data/lib/fluid_cli/theme/syncer/standard_reporter.rb +32 -0
  66. data/lib/fluid_cli/theme/syncer/unsupported_script_warning.rb +90 -0
  67. data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all.rb +41 -0
  68. data/lib/fluid_cli/theme/syncer/uploader/forms/apply_to_all_form.rb +37 -0
  69. data/lib/fluid_cli/theme/syncer/uploader/forms/base_strategy_form.rb +64 -0
  70. data/lib/fluid_cli/theme/syncer/uploader/forms/select_delete_strategy.rb +29 -0
  71. data/lib/fluid_cli/theme/syncer/uploader/forms/select_update_strategy.rb +30 -0
  72. data/lib/fluid_cli/theme/syncer/uploader/json_delete_handler.rb +49 -0
  73. data/lib/fluid_cli/theme/syncer/uploader/json_update_handler.rb +71 -0
  74. data/lib/fluid_cli/theme/syncer/uploader.rb +105 -0
  75. data/lib/fluid_cli/theme/syncer.rb +412 -0
  76. data/lib/fluid_cli/theme/theme.rb +186 -0
  77. data/lib/fluid_cli/theme/ui/sync_progress_bar.rb +22 -0
  78. data/lib/fluid_cli/thread_pool/job.rb +35 -0
  79. data/lib/fluid_cli/thread_pool.rb +49 -0
  80. data/lib/fluid_cli/version.rb +3 -0
  81. data/lib/fluid_cli.rb +59 -0
  82. data/vendor/deps/base64/.document +5 -0
  83. data/vendor/deps/base64/.gitignore +9 -0
  84. data/vendor/deps/base64/BSDL +22 -0
  85. data/vendor/deps/base64/COPYING +56 -0
  86. data/vendor/deps/base64/Gemfile +9 -0
  87. data/vendor/deps/base64/LEGAL +60 -0
  88. data/vendor/deps/base64/README.md +48 -0
  89. data/vendor/deps/base64/Rakefile +31 -0
  90. data/vendor/deps/base64/base64.gemspec +28 -0
  91. data/vendor/deps/base64/bin/console +14 -0
  92. data/vendor/deps/base64/bin/setup +8 -0
  93. data/vendor/deps/base64/lib/base64.rb +382 -0
  94. data/vendor/deps/base64/sig/base64.rbs +358 -0
  95. data/vendor/deps/base64/test/base64/test_base64.rb +115 -0
  96. data/vendor/deps/base64/test_sig/test_base64.rb +44 -0
  97. data/vendor/deps/cli-kit/REVISION +1 -0
  98. data/vendor/deps/cli-kit/lib/cli/kit/args/definition.rb +286 -0
  99. data/vendor/deps/cli-kit/lib/cli/kit/args/evaluation.rb +215 -0
  100. data/vendor/deps/cli-kit/lib/cli/kit/args/parser/node.rb +128 -0
  101. data/vendor/deps/cli-kit/lib/cli/kit/args/parser.rb +125 -0
  102. data/vendor/deps/cli-kit/lib/cli/kit/args/tokenizer.rb +130 -0
  103. data/vendor/deps/cli-kit/lib/cli/kit/args.rb +16 -0
  104. data/vendor/deps/cli-kit/lib/cli/kit/base_command.rb +30 -0
  105. data/vendor/deps/cli-kit/lib/cli/kit/command_help.rb +268 -0
  106. data/vendor/deps/cli-kit/lib/cli/kit/command_registry.rb +150 -0
  107. data/vendor/deps/cli-kit/lib/cli/kit/config.rb +137 -0
  108. data/vendor/deps/cli-kit/lib/cli/kit/core_ext.rb +28 -0
  109. data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +166 -0
  110. data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +92 -0
  111. data/vendor/deps/cli-kit/lib/cli/kit/ini.rb +91 -0
  112. data/vendor/deps/cli-kit/lib/cli/kit/levenshtein.rb +92 -0
  113. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +94 -0
  114. data/vendor/deps/cli-kit/lib/cli/kit/opts.rb +248 -0
  115. data/vendor/deps/cli-kit/lib/cli/kit/parse_args.rb +55 -0
  116. data/vendor/deps/cli-kit/lib/cli/kit/resolver.rb +66 -0
  117. data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +260 -0
  118. data/vendor/deps/cli-kit/lib/cli/kit/support.rb +11 -0
  119. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +290 -0
  120. data/vendor/deps/cli-kit/lib/cli/kit/util.rb +118 -0
  121. data/vendor/deps/cli-kit/lib/cli/kit/version.rb +7 -0
  122. data/vendor/deps/cli-kit/lib/cli/kit.rb +139 -0
  123. data/vendor/deps/cli-ui/REVISION +1 -0
  124. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +218 -0
  125. data/vendor/deps/cli-ui/lib/cli/ui/color.rb +101 -0
  126. data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +219 -0
  127. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +67 -0
  128. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +179 -0
  129. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +152 -0
  130. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +127 -0
  131. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +286 -0
  132. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +92 -0
  133. data/vendor/deps/cli-ui/lib/cli/ui/os.rb +63 -0
  134. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +64 -0
  135. data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +132 -0
  136. data/vendor/deps/cli-ui/lib/cli/ui/progress_reporter.rb +209 -0
  137. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +583 -0
  138. data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +36 -0
  139. data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +381 -0
  140. data/vendor/deps/cli-ui/lib/cli/ui/spinner/async.rb +48 -0
  141. data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +602 -0
  142. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +79 -0
  143. data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +399 -0
  144. data/vendor/deps/cli-ui/lib/cli/ui/table.rb +83 -0
  145. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +55 -0
  146. data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +106 -0
  147. data/vendor/deps/cli-ui/lib/cli/ui/version.rb +8 -0
  148. data/vendor/deps/cli-ui/lib/cli/ui/widgets/base.rb +46 -0
  149. data/vendor/deps/cli-ui/lib/cli/ui/widgets/status.rb +79 -0
  150. data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +89 -0
  151. data/vendor/deps/cli-ui/lib/cli/ui/work_queue.rb +142 -0
  152. data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +61 -0
  153. data/vendor/deps/cli-ui/lib/cli/ui.rb +359 -0
  154. data/vendor/deps/cli-ui/vendor/reentrant_mutex.rb +78 -0
  155. data/vendor/deps/debug/CONTRIBUTING.md +573 -0
  156. data/vendor/deps/debug/Gemfile +10 -0
  157. data/vendor/deps/debug/LICENSE.txt +22 -0
  158. data/vendor/deps/debug/README.md +996 -0
  159. data/vendor/deps/debug/Rakefile +57 -0
  160. data/vendor/deps/debug/TODO.md +23 -0
  161. data/vendor/deps/debug/debug.gemspec +33 -0
  162. data/vendor/deps/debug/exe/rdbg +53 -0
  163. data/vendor/deps/debug/ext/debug/Makefile +273 -0
  164. data/vendor/deps/debug/ext/debug/debug.c +228 -0
  165. data/vendor/deps/debug/ext/debug/debug_version.h +1 -0
  166. data/vendor/deps/debug/ext/debug/extconf.rb +27 -0
  167. data/vendor/deps/debug/ext/debug/iseq_collector.c +93 -0
  168. data/vendor/deps/debug/lib/debug/abbrev_command.rb +77 -0
  169. data/vendor/deps/debug/lib/debug/breakpoint.rb +556 -0
  170. data/vendor/deps/debug/lib/debug/client.rb +263 -0
  171. data/vendor/deps/debug/lib/debug/color.rb +123 -0
  172. data/vendor/deps/debug/lib/debug/config.rb +592 -0
  173. data/vendor/deps/debug/lib/debug/console.rb +224 -0
  174. data/vendor/deps/debug/lib/debug/dap_custom/traceInspector.rb +336 -0
  175. data/vendor/deps/debug/lib/debug/debug.bundle +0 -0
  176. data/vendor/deps/debug/lib/debug/frame_info.rb +190 -0
  177. data/vendor/deps/debug/lib/debug/irb_integration.rb +37 -0
  178. data/vendor/deps/debug/lib/debug/local.rb +115 -0
  179. data/vendor/deps/debug/lib/debug/open.rb +13 -0
  180. data/vendor/deps/debug/lib/debug/open_nonstop.rb +15 -0
  181. data/vendor/deps/debug/lib/debug/prelude.rb +50 -0
  182. data/vendor/deps/debug/lib/debug/server.rb +534 -0
  183. data/vendor/deps/debug/lib/debug/server_cdp.rb +1348 -0
  184. data/vendor/deps/debug/lib/debug/server_dap.rb +1108 -0
  185. data/vendor/deps/debug/lib/debug/session.rb +2667 -0
  186. data/vendor/deps/debug/lib/debug/source_repository.rb +150 -0
  187. data/vendor/deps/debug/lib/debug/start.rb +5 -0
  188. data/vendor/deps/debug/lib/debug/thread_client.rb +1457 -0
  189. data/vendor/deps/debug/lib/debug/tracer.rb +241 -0
  190. data/vendor/deps/debug/lib/debug/version.rb +5 -0
  191. data/vendor/deps/debug/lib/debug.rb +9 -0
  192. data/vendor/deps/debug/misc/README.md.erb +660 -0
  193. data/vendor/deps/listen/.github/release-drafter.yml +17 -0
  194. data/vendor/deps/listen/.github/workflows/development.yml +67 -0
  195. data/vendor/deps/listen/.github/workflows/push.yml +12 -0
  196. data/vendor/deps/listen/.gitignore +28 -0
  197. data/vendor/deps/listen/.rspec +3 -0
  198. data/vendor/deps/listen/.rubocop.yml +283 -0
  199. data/vendor/deps/listen/.yardopts +11 -0
  200. data/vendor/deps/listen/CHANGELOG.md +1 -0
  201. data/vendor/deps/listen/CONTRIBUTING.md +45 -0
  202. data/vendor/deps/listen/Gemfile +33 -0
  203. data/vendor/deps/listen/Guardfile +26 -0
  204. data/vendor/deps/listen/LICENSE.txt +22 -0
  205. data/vendor/deps/listen/README.md +490 -0
  206. data/vendor/deps/listen/Rakefile +154 -0
  207. data/vendor/deps/listen/bin/listen +11 -0
  208. data/vendor/deps/listen/lib/listen/adapter/base.rb +129 -0
  209. data/vendor/deps/listen/lib/listen/adapter/bsd.rb +104 -0
  210. data/vendor/deps/listen/lib/listen/adapter/config.rb +31 -0
  211. data/vendor/deps/listen/lib/listen/adapter/darwin.rb +77 -0
  212. data/vendor/deps/listen/lib/listen/adapter/linux.rb +108 -0
  213. data/vendor/deps/listen/lib/listen/adapter/polling.rb +40 -0
  214. data/vendor/deps/listen/lib/listen/adapter/windows.rb +96 -0
  215. data/vendor/deps/listen/lib/listen/adapter.rb +43 -0
  216. data/vendor/deps/listen/lib/listen/backend.rb +40 -0
  217. data/vendor/deps/listen/lib/listen/change.rb +69 -0
  218. data/vendor/deps/listen/lib/listen/cli.rb +65 -0
  219. data/vendor/deps/listen/lib/listen/directory.rb +93 -0
  220. data/vendor/deps/listen/lib/listen/error.rb +11 -0
  221. data/vendor/deps/listen/lib/listen/event/config.rb +39 -0
  222. data/vendor/deps/listen/lib/listen/event/loop.rb +92 -0
  223. data/vendor/deps/listen/lib/listen/event/processor.rb +128 -0
  224. data/vendor/deps/listen/lib/listen/event/queue.rb +52 -0
  225. data/vendor/deps/listen/lib/listen/file.rb +95 -0
  226. data/vendor/deps/listen/lib/listen/fsm.rb +131 -0
  227. data/vendor/deps/listen/lib/listen/listener/config.rb +41 -0
  228. data/vendor/deps/listen/lib/listen/listener.rb +136 -0
  229. data/vendor/deps/listen/lib/listen/logger.rb +65 -0
  230. data/vendor/deps/listen/lib/listen/monotonic_time.rb +27 -0
  231. data/vendor/deps/listen/lib/listen/options.rb +24 -0
  232. data/vendor/deps/listen/lib/listen/queue_optimizer.rb +129 -0
  233. data/vendor/deps/listen/lib/listen/record/entry.rb +66 -0
  234. data/vendor/deps/listen/lib/listen/record/symlink_detector.rb +47 -0
  235. data/vendor/deps/listen/lib/listen/record.rb +122 -0
  236. data/vendor/deps/listen/lib/listen/silencer/controller.rb +50 -0
  237. data/vendor/deps/listen/lib/listen/silencer.rb +106 -0
  238. data/vendor/deps/listen/lib/listen/thread.rb +54 -0
  239. data/vendor/deps/listen/lib/listen/version.rb +5 -0
  240. data/vendor/deps/listen/lib/listen.rb +47 -0
  241. data/vendor/deps/listen/listen.gemspec +40 -0
  242. data/vendor/deps/listen/spec/acceptance/listen_spec.rb +320 -0
  243. data/vendor/deps/listen/spec/lib/listen/adapter/base_spec.rb +101 -0
  244. data/vendor/deps/listen/spec/lib/listen/adapter/bsd_spec.rb +13 -0
  245. data/vendor/deps/listen/spec/lib/listen/adapter/config_spec.rb +122 -0
  246. data/vendor/deps/listen/spec/lib/listen/adapter/darwin_spec.rb +82 -0
  247. data/vendor/deps/listen/spec/lib/listen/adapter/linux_spec.rb +199 -0
  248. data/vendor/deps/listen/spec/lib/listen/adapter/polling_spec.rb +83 -0
  249. data/vendor/deps/listen/spec/lib/listen/adapter/windows_spec.rb +13 -0
  250. data/vendor/deps/listen/spec/lib/listen/adapter_spec.rb +69 -0
  251. data/vendor/deps/listen/spec/lib/listen/backend_spec.rb +82 -0
  252. data/vendor/deps/listen/spec/lib/listen/change_spec.rb +102 -0
  253. data/vendor/deps/listen/spec/lib/listen/cli_spec.rb +116 -0
  254. data/vendor/deps/listen/spec/lib/listen/directory_spec.rb +284 -0
  255. data/vendor/deps/listen/spec/lib/listen/event/config_spec.rb +33 -0
  256. data/vendor/deps/listen/spec/lib/listen/event/loop_spec.rb +118 -0
  257. data/vendor/deps/listen/spec/lib/listen/event/processor_spec.rb +250 -0
  258. data/vendor/deps/listen/spec/lib/listen/event/queue_spec.rb +118 -0
  259. data/vendor/deps/listen/spec/lib/listen/file_spec.rb +254 -0
  260. data/vendor/deps/listen/spec/lib/listen/fsm_spec.rb +147 -0
  261. data/vendor/deps/listen/spec/lib/listen/listener/config_spec.rb +29 -0
  262. data/vendor/deps/listen/spec/lib/listen/listener_spec.rb +321 -0
  263. data/vendor/deps/listen/spec/lib/listen/logger_spec.rb +212 -0
  264. data/vendor/deps/listen/spec/lib/listen/monotonic_time_spec.rb +58 -0
  265. data/vendor/deps/listen/spec/lib/listen/queue_optimizer_spec.rb +111 -0
  266. data/vendor/deps/listen/spec/lib/listen/record_spec.rb +424 -0
  267. data/vendor/deps/listen/spec/lib/listen/silencer/controller_spec.rb +97 -0
  268. data/vendor/deps/listen/spec/lib/listen/silencer_spec.rb +109 -0
  269. data/vendor/deps/listen/spec/lib/listen/thread_spec.rb +133 -0
  270. data/vendor/deps/listen/spec/lib/listen_spec.rb +25 -0
  271. data/vendor/deps/listen/spec/spec_helper.rb +49 -0
  272. data/vendor/deps/listen/spec/support/acceptance_helper.rb +260 -0
  273. data/vendor/deps/listen/spec/support/fixtures_helper.rb +32 -0
  274. data/vendor/deps/listen/spec/support/platform_helper.rb +17 -0
  275. data/vendor/deps/observer/.github/dependabot.yml +6 -0
  276. data/vendor/deps/observer/.github/workflows/test.yml +33 -0
  277. data/vendor/deps/observer/.gitignore +8 -0
  278. data/vendor/deps/observer/BSDL +22 -0
  279. data/vendor/deps/observer/COPYING +56 -0
  280. data/vendor/deps/observer/Gemfile +9 -0
  281. data/vendor/deps/observer/README.md +139 -0
  282. data/vendor/deps/observer/Rakefile +10 -0
  283. data/vendor/deps/observer/bin/console +14 -0
  284. data/vendor/deps/observer/bin/setup +8 -0
  285. data/vendor/deps/observer/lib/observer.rb +229 -0
  286. data/vendor/deps/observer/observer.gemspec +32 -0
  287. data/vendor/deps/observer/test/test_observer.rb +66 -0
  288. data/vendor/deps/webrick/.gitignore +9 -0
  289. data/vendor/deps/webrick/Gemfile +3 -0
  290. data/vendor/deps/webrick/LICENSE.txt +22 -0
  291. data/vendor/deps/webrick/README.md +61 -0
  292. data/vendor/deps/webrick/Rakefile +10 -0
  293. data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
  294. data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
  295. data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
  296. data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
  297. data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
  298. data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
  299. data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
  300. data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
  301. data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
  302. data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
  303. data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
  304. data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
  305. data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
  306. data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
  307. data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
  308. data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
  309. data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
  310. data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
  311. data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
  312. data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
  313. data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  314. data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
  315. data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
  316. data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
  317. data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
  318. data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
  319. data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
  320. data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
  321. data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
  322. data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
  323. data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
  324. data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
  325. data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
  326. data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
  327. data/vendor/deps/webrick/lib/webrick.rb +232 -0
  328. data/vendor/deps/webrick/webrick.gemspec +74 -0
  329. metadata +412 -0
@@ -0,0 +1,691 @@
1
+ # frozen_string_literal: true
2
+ require "fluid_cli"
3
+ require "fileutils"
4
+ require "rbconfig"
5
+ require "net/http"
6
+ require "json"
7
+ require "bundler"
8
+
9
+ module FluidCLI
10
+ ##
11
+ # Context captures a lot about the current running command. It captures the
12
+ # environment, output, system and file operations. It is useful to have the
13
+ # context especially in tests so that you have a single access point to these
14
+ # resoures.
15
+ #
16
+ class Context
17
+ GEM_LATEST_URI = URI.parse("https://rubygems.org/api/v1/versions/fluid-cli/latest.json")
18
+ VERSION_CHECK_SECTION = "versioncheck"
19
+ LAST_CHECKED_AT_FIELD = "last_checked_at"
20
+ LATEST_VERSION_FIELD = "latest_version"
21
+ VERSION_CHECK_INTERVAL = 86400
22
+
23
+ class << self
24
+ attr_reader :messages
25
+
26
+ # adds a new set of messages to be used by the CLI. The messages are expected to be a hash of symbols, and
27
+ # multiple levels are allowed. When fetching messages a dot notation is used to separate different levels. See
28
+ # Context::message for more information.
29
+ #
30
+ # #### Parameters
31
+ # * `messages` - Hash containing the new keys to register
32
+ def load_messages(messages)
33
+ @messages ||= {}
34
+ @messages = @messages.merge(messages) do |key|
35
+ Context.new.abort("Message key '#{key}' already exists and cannot be registered") if @messages.key?(key)
36
+ end
37
+ end
38
+
39
+ # returns the user-facing messages for the given key. Returns the key if no message is available.
40
+ #
41
+ # #### Parameters
42
+ # * `key` - a symbol representing the message
43
+ # * `params` - the parameters to format the string with
44
+ def message(key, *params)
45
+ key_parts = key.split(".").map(&:to_sym)
46
+ str = Context.messages.dig(*key_parts)
47
+ str ? str % params : key
48
+ end
49
+
50
+ # a wrapper around Kernel.puts to allow for easy formatting
51
+ #
52
+ # #### Parameters
53
+ # * `text` - a string message to output
54
+ def puts(*args)
55
+ Kernel.puts(CLI::UI.fmt(*args))
56
+ end
57
+
58
+ # aborts the current running command and outputs an error message:
59
+ # - when the `help_message` is not provided, the error message appears in
60
+ # a red frame, prefixed by an ✗ icon
61
+ # - when the `help_message` is provided, the error message appears in a
62
+ # red frame, and the help message appears in a green frame
63
+ #
64
+ # #### Parameters
65
+ # * `error_message` - an error message to output
66
+ # * `help_message` - an optional help message
67
+ #
68
+ # #### Example
69
+ #
70
+ # FluidCLI::Context.abort("Execution error")
71
+ # # Output:
72
+ # # ┏━━ Error ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
73
+ # # ┃ ✗ Execution error
74
+ # # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
75
+ #
76
+ # FluidCLI::Context.abort("Execution error", "export EXECUTION=1")
77
+ # # Output:
78
+ # # ┏━━ Error ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
79
+ # # ┃ Execution error
80
+ # # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
81
+ # # ┏━━ Try this ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
82
+ # # ┃ export EXECUTION=1
83
+ # # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
84
+ #
85
+ def abort(error_message, help_message = nil)
86
+ raise CLI::Kit::Abort, "{{x}} #{error_message}" if help_message.nil?
87
+
88
+ frame("Error", color: :red) { self.puts(error_message) }
89
+ frame("Try this", color: :green) { self.puts(help_message) }
90
+
91
+ raise CLI::Kit::AbortSilent
92
+ end
93
+
94
+ private
95
+
96
+ def frame(title, color:, &block)
97
+ CLI::UI::Frame.open(title, color: CLI::UI.resolve_color(color), timing: false, &block)
98
+ end
99
+ end
100
+
101
+ # is the directory root that the current command is running in. If you want to
102
+ # simulate a `cd` for the file operations, you can change this variable.
103
+ attr_accessor :root
104
+ # is an accessor for environment variables. These variables are also added to
105
+ # any command run by the context.
106
+ attr_accessor :env
107
+
108
+ def initialize(root: Dir.pwd, env: ($original_env || ENV).to_h) # :nodoc:
109
+ self.root = root
110
+ self.env = env
111
+ end
112
+
113
+ # will return which operating system that the cli is running on [:mac, :linux]
114
+ def os
115
+ host = uname
116
+ return :mac_m1 if /arm64.*darwin/i.match(host)
117
+ return :mac if /darwin/i.match(host)
118
+ return :windows if /mswin|mingw|cygwin/i.match(host)
119
+ return :linux if /linux|bsd/i.match(host)
120
+ :unknown
121
+ end
122
+
123
+ # will return true if the cli is running on an ARM Apple computer.
124
+ def mac_m1?
125
+ os == :mac_m1
126
+ end
127
+
128
+ # will return true if the cli is running on a Intel x86 Apple computer.
129
+ def mac?
130
+ os == :mac
131
+ end
132
+
133
+ # will return true if the cli is running on a linux distro
134
+ def linux?
135
+ os == :linux
136
+ end
137
+
138
+ # will return true if the cli is running on Windows
139
+ def windows?
140
+ os == :windows
141
+ end
142
+
143
+ # will return true if the os is unknown
144
+ def unknown_os?
145
+ os == :unknown
146
+ end
147
+
148
+ # will return true if being launched from a tty
149
+ def tty?
150
+ $stdin.tty?
151
+ end
152
+
153
+ # will return true if the cli is being run from an installation, and not a
154
+ # development instance. The gem installation will not have a 'test' directory.
155
+ # See `#development?` for checking for development environment.
156
+ #
157
+ def system?
158
+ !Dir.exist?(File.join(FluidCLI::ROOT, "test"))
159
+ end
160
+
161
+ # will return true if the cli is running on your development instance.
162
+ #
163
+ def development?
164
+ !system? && !testing?
165
+ end
166
+
167
+ # will return true while tests are running, either locally or on CI
168
+ def testing?
169
+ ci? || ENV["FLUID_CLI_TEST"]
170
+ end
171
+
172
+ ##
173
+ # will return true if the cli is being tested on CI
174
+ def ci?
175
+ ENV["CI"]
176
+ end
177
+
178
+ ##
179
+ # will return true if the cli is running with the DEBUG flag
180
+ def debug?
181
+ getenv("DEBUG")
182
+ end
183
+
184
+ # get a environment variable value by name.
185
+ #
186
+ # #### Parameters
187
+ # * `name` - the name of the environment variable that you want to fetch
188
+ #
189
+ # #### Returns
190
+ # * `value` - will return the value, or nil if the variable does not exist
191
+ #
192
+ def getenv(name)
193
+ v = @env[name]
194
+ v == "" ? nil : v
195
+ end
196
+
197
+ # set a environment variable value by name.
198
+ #
199
+ # #### Parameters
200
+ # * `key` - the name of the environment variable that you want to set
201
+ # * `value` - the value of the variable
202
+ #
203
+ def setenv(key, value)
204
+ @env[key] = value
205
+ end
206
+
207
+ # will write/overwrite a file with the provided contents, relative to the context root
208
+ # unless the file path is absolute.
209
+ #
210
+ # #### Parameters
211
+ # * `fname` - filename of the file that you are writing, relative to root unless it is absolute.
212
+ # * `content` - the body contents of the file that you are writing
213
+ #
214
+ # #### Example
215
+ #
216
+ # @ctx.write('new.txt', 'hello world')
217
+ #
218
+ def write(fname, content)
219
+ File.write(ctx_path(fname), content)
220
+ end
221
+
222
+ # will read a file relative to the context root unless the file path is absolute.
223
+ #
224
+ # #### Parameters
225
+ # * `fname` - filename of the file that you are reading, relative to root unless it is absolute.
226
+ #
227
+ # #### Example
228
+ #
229
+ # @ctx.read('file.txt')
230
+ #
231
+ def read(fname)
232
+ File.read(ctx_path(fname))
233
+ end
234
+
235
+ # will read a binary file relative to the context root unless the file path is absolute.
236
+ #
237
+ # #### Parameters
238
+ # * `fname` - filename of the file that you are reading, relative to root unless it is absolute.
239
+ #
240
+ # #### Example
241
+ #
242
+ # @ctx.read('binary.out')
243
+ #
244
+ def binread(fname)
245
+ File.binread(ctx_path(fname))
246
+ end
247
+
248
+ # will write/overwrite a binary file with the provided contents, relative to the context root
249
+ # unless the file path is absolute.
250
+ #
251
+ # #### Parameters
252
+ # * `fname` - filename of the file that you are writing, relative to root unless it is absolute.
253
+ # * `content` - the body contents of the file that you are writing
254
+ #
255
+ # #### Example
256
+ #
257
+ # @ctx.binwrite('binary.out', 'ASCII-8BIT encoded binary')
258
+ #
259
+ def binwrite(fname, content)
260
+ File.binwrite(ctx_path(fname), content)
261
+ end
262
+
263
+ # will change directories and update the root, the filepath is relative to the command root unless absolute
264
+ #
265
+ # #### Parameters
266
+ # * `path` - the file path to a directory, relative to the context root to remove from the FS
267
+ #
268
+ def chdir(path)
269
+ Dir.chdir(ctx_path(path))
270
+ self.root = ctx_path(path)
271
+ end
272
+
273
+ # checks if a directory exists, the filepath is relative to the command root unless absolute
274
+ #
275
+ # #### Parameters
276
+ # * `path` - the file path to a directory, relative to the context root to remove from the FS
277
+ #
278
+ def dir_exist?(path)
279
+ Dir.exist?(ctx_path(path))
280
+ end
281
+
282
+ # checks if a file exists, the filepath is relative to the command root unless absolute
283
+ #
284
+ # #### Parameters
285
+ # * `path` - the file path to a file, relative to the context root to remove from the FS
286
+ #
287
+ def file_exist?(path)
288
+ File.exist?(ctx_path(path))
289
+ end
290
+
291
+ # will recursively copy a directory from the FS, the filepath is relative to the command
292
+ # root unless absolute
293
+ #
294
+ # #### Parameters
295
+ # * `from` - the path of the original file
296
+ # * `to` - the destination path
297
+ #
298
+ def cp_r(from, to)
299
+ FileUtils.cp_r(ctx_path(from), ctx_path(to))
300
+ end
301
+
302
+ # will copy a directory from the FS, the filepath is relative to the command
303
+ # root unless absolute
304
+ #
305
+ # #### Parameters
306
+ # * `from` - the path of the original file
307
+ # * `to` - the destination path
308
+ #
309
+ def cp(from, to)
310
+ FileUtils.cp(ctx_path(from), ctx_path(to))
311
+ end
312
+
313
+ # will rename a file from one place to another, relative to the command root
314
+ # unless the path is absolute.
315
+ #
316
+ # #### Parameters
317
+ # * `from` - the path of the original file
318
+ # * `to` - the destination path
319
+ #
320
+ def rename(from, to)
321
+ File.rename(ctx_path(from), ctx_path(to))
322
+ end
323
+
324
+ # will remove a plain file from the FS, the filepath is relative to the command
325
+ # root unless absolute.
326
+ #
327
+ # #### Parameters
328
+ # * `fname` - the file path relative to the context root to remove from the FS
329
+ #
330
+ def rm(fname)
331
+ FileUtils.rm(ctx_path(fname))
332
+ end
333
+
334
+ # will remove a directory from the FS, the filepath is relative to the command
335
+ # root unless absolute
336
+ #
337
+ # #### Parameters
338
+ # * `fname` - the file path to a directory, relative to the context root to remove from the FS
339
+ #
340
+ def rm_r(fname)
341
+ FileUtils.rm_r(ctx_path(fname))
342
+ end
343
+
344
+ # will force remove a directory from the FS, the filepath is relative to the command
345
+ # root unless absolute
346
+ #
347
+ # #### Parameters
348
+ # * `fname` - the file path to a directory, relative to the context root to remove from the FS
349
+ #
350
+ def rm_rf(fname)
351
+ FileUtils.rm_rf(ctx_path(fname))
352
+ end
353
+
354
+ # will create a directory, recursively if it does not exist. So if you create
355
+ # a directory `foo/bar/dun`, this will also create the directories `foo` and
356
+ # `foo/bar` if they do not exist. The path will be made relative to the command
357
+ # root unless absolute
358
+ #
359
+ # #### Parameters
360
+ # * `path` - file path of the directory that you want to create
361
+ #
362
+ def mkdir_p(path)
363
+ FileUtils.mkdir_p(path)
364
+ end
365
+
366
+ # will output to the console a link for the user to either copy/paste
367
+ # or click on.
368
+ #
369
+ # #### Parameters
370
+ # * `uri` - a http URI to open in a browser
371
+ #
372
+ def open_url!(uri)
373
+ help = "Please open this URL in your browser:\n #{uri}"
374
+ puts(help)
375
+ end
376
+
377
+ # will output to the console a link for the user to either copy/paste
378
+ # or click on.
379
+ #
380
+ # #### Parameters
381
+ # * `uri` - a http URI to open in a browser
382
+ #
383
+ def open_browser_url!(uri)
384
+ if tty?
385
+ if linux? && which("xdg-open")
386
+ system("xdg-open", uri.to_s)
387
+ elsif windows?
388
+ system("start \"\" \"#{uri}\"")
389
+ elsif mac? || mac_m1?
390
+ system("open", uri.to_s)
391
+ else
392
+ open_url!(uri)
393
+ end
394
+ else
395
+ open_url!(uri)
396
+ end
397
+ end
398
+
399
+ # will output a message, prefixed by a yellow star, indicating that task
400
+ # started.
401
+ #
402
+ # #### Parameters
403
+ # * `text` - a string message to output
404
+ #
405
+ def print_task(text)
406
+ puts "{{yellow:*}} #{text}"
407
+ end
408
+
409
+ # proxy call to Context.puts.
410
+ #
411
+ # #### Parameters
412
+ # * `text` - a string message to output
413
+ #
414
+ def puts(*args)
415
+ Context.puts(*args)
416
+ end
417
+
418
+ # a wrapper around $stderr.puts to allow for easy formatting
419
+ #
420
+ # #### Parameters
421
+ # * `text` - a string message to output
422
+ #
423
+ def error(text)
424
+ $stderr.puts(CLI::UI.fmt(text))
425
+ end
426
+
427
+ # a wrapper around Kernel.warn to allow for easy formatting
428
+ #
429
+ # #### Parameters
430
+ # * `text` - a string message to output
431
+ #
432
+ def warn(*args)
433
+ Kernel.warn(CLI::UI.fmt(*args))
434
+ end
435
+
436
+ # outputs a message, prefixed by a checkmark indicating that something completed
437
+ #
438
+ # #### Parameters
439
+ # * `text` - a string message to output
440
+ #
441
+ def done(text)
442
+ puts("{{v}} #{text}")
443
+ end
444
+
445
+ # proxy call to Context.abort.
446
+ #
447
+ # #### Parameters
448
+ # * `error_message` - an error message to output
449
+ # * `help_message` - an optional help message
450
+ def abort(error_message, help_message = nil)
451
+ Context.abort(error_message, help_message)
452
+ end
453
+
454
+ # outputs a message, prefixed by a red `DEBUG` tag. This will only output to
455
+ # the console if you have `DEBUG=1` set in your shell environment.
456
+ #
457
+ # #### Parameters
458
+ # * `text` - a string message to output
459
+ #
460
+ def debug(text)
461
+ puts("{{red:DEBUG}} #{text}") if debug?
462
+ end
463
+
464
+ # proxy call to Context.message.
465
+ #
466
+ # #### Parameters
467
+ # * `key` - a symbol representing the message
468
+ # * `params` - the parameters to format the string with
469
+ def message(key, *params)
470
+ Context.message(key, *params)
471
+ end
472
+
473
+ # will grab the host info of the computer running the cli. This indicates the
474
+ # computer architecture and operating system
475
+ def uname
476
+ @uname ||= RbConfig::CONFIG["host"]
477
+ end
478
+
479
+ # Execute a command in the user's environment
480
+ # Outputs result of the command without capturing it
481
+ #
482
+ # #### Parameters
483
+ # - `*args`: A splat of arguments evaluated as a command. (e.g. `'rm', folder` is equivalent to `rm #{folder}`)
484
+ # - `**kwargs`: additional keyword arguments to pass to Process.spawn
485
+ #
486
+ # #### Returns
487
+ # - `status`: The `Process::Status` result of the command execution.
488
+ #
489
+ # #### Usage
490
+ #
491
+ # stat = @ctx.system('ls', 'a_folder')
492
+ #
493
+ def system(*args, **kwargs)
494
+ process_status = CLI::Kit::System.system(*args, env: @env, **kwargs)
495
+ unless process_status.success?
496
+ abort("System call failed: #{args.join(" ")}")
497
+ end
498
+ process_status
499
+ end
500
+
501
+ # Execute a command in the user's environment
502
+ # This is meant to be largely equivalent to backticks, only with the env passed in.
503
+ # Captures the results of the command without output to the console
504
+ #
505
+ # #### Parameters
506
+ # - `*args`: A splat of arguments evaluated as a command. (e.g. `'rm', folder` is equivalent to `rm #{folder}`)
507
+ # - `**kwargs`: additional arguments to pass to Open3.capture2
508
+ #
509
+ # #### Returns
510
+ # - `output`: output (STDOUT) of the command execution
511
+ # - `status`: boolean success status of the command execution
512
+ #
513
+ # #### Usage
514
+ #
515
+ # out, stat = @ctx.capture2('ls', 'a_folder')
516
+ #
517
+ def capture2(*args, **kwargs)
518
+ CLI::Kit::System.capture2(*args, env: @env, **kwargs)
519
+ end
520
+
521
+ # Execute a command in the user's environment
522
+ # This is meant to be largely equivalent to backticks, only with the env passed in.
523
+ # Captures the results of the command without output to the console
524
+ #
525
+ # #### Parameters
526
+ # - `*args`: A splat of arguments evaluated as a command. (e.g. `'rm', folder` is equivalent to `rm #{folder}`)
527
+ # - `**kwargs`: additional arguments to pass to Open3.capture2e
528
+ #
529
+ # #### Returns
530
+ # - `output`: output (STDOUT merged with STDERR) of the command execution
531
+ # - `status`: boolean success status of the command execution
532
+ #
533
+ # #### Usage
534
+ #
535
+ # out_and_err, stat = @ctx.capture2e('ls', 'a_folder')
536
+ #
537
+ def capture2e(*args, **kwargs)
538
+ CLI::Kit::System.capture2e(*args, env: @env, **kwargs)
539
+ end
540
+
541
+ # Execute a command in the user's environment
542
+ # This is meant to be largely equivalent to backticks, only with the env passed in.
543
+ # Captures the results of the command without output to the console
544
+ #
545
+ # #### Parameters
546
+ # - `*args`: A splat of arguments evaluated as a command. (e.g. `'rm', folder` is equivalent to `rm #{folder}`)
547
+ # - `**kwargs`: additional arguments to pass to Open3.capture3
548
+ #
549
+ # #### Returns
550
+ # - `output`: STDOUT of the command execution
551
+ # - `error`: STDERR of the command execution
552
+ # - `status`: boolean success status of the command execution
553
+ #
554
+ # #### Usage
555
+ #
556
+ # out, err, stat = @ctx.capture3('ls', 'a_folder')
557
+ #
558
+ def capture3(*args, **kwargs)
559
+ CLI::Kit::System.capture3(*args, env: @env, **kwargs)
560
+ end
561
+
562
+ # captures the info signal (ctrl-T) and provide a handler to it.
563
+ #
564
+ # #### Example
565
+ #
566
+ # @ctx.on_siginfo do
567
+ # @ctx.open_url!("http://google.com")
568
+ # end
569
+ #
570
+ def on_siginfo
571
+ # Reset any previous SIGINFO handling we had so the only action we take is the given block
572
+ trap("INFO", "DEFAULT")
573
+
574
+ fork do
575
+ r, w = IO.pipe
576
+ @signal = false
577
+ trap("SIGINFO") do
578
+ @signal = true
579
+ w.write(0)
580
+ end
581
+ while r.read(1)
582
+ next unless @signal
583
+ @signal = false
584
+ yield
585
+ end
586
+ rescue Interrupt
587
+ exit(0)
588
+ end
589
+ end
590
+
591
+ # Checks if the given command exists in the system
592
+ #
593
+ # #### Parameters
594
+ # - `cmd`: The command to test
595
+ #
596
+ # #### Returns
597
+ # The path of the executable if it is found
598
+ #
599
+ # @todo This is currently a duplicate of CLI::Kit::System.which() - we should make that method public when we make
600
+ # Kit changes and make this a wrapper instead.
601
+ def which(cmd)
602
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
603
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
604
+ exts.each do |ext|
605
+ exe = File.join(File.expand_path(path), "#{cmd}#{ext}")
606
+ return exe if File.executable?(exe) && !File.directory?(exe)
607
+ end
608
+ end
609
+
610
+ nil
611
+ end
612
+
613
+ # Checks if there's a newer version of the CLI available and returns version string if
614
+ # this should be conveyed to the user (i.e., if it's been over 24 hours since last check)
615
+ #
616
+ # #### Parameters
617
+ #
618
+ # #### Returns
619
+ # - `version`: string of newer version available, IFF new version is available AND it's time to inform user,
620
+ # : nil otherwise
621
+ #
622
+ def new_version
623
+ if (time_of_last_check + VERSION_CHECK_INTERVAL) < (Time.now.to_i)
624
+ # Fork is not supported in Windows
625
+ if Process.respond_to?(:fork)
626
+ fork { retrieve_latest_gem_version }
627
+ else
628
+ thread = Thread.new { retrieve_latest_gem_version }
629
+ at_exit { thread.join }
630
+ end
631
+ latest_version =
632
+ FluidCLI::Config.get(VERSION_CHECK_SECTION, LATEST_VERSION_FIELD, default: FluidCLI::VERSION)
633
+ latest_version if ::Semantic::Version.new(latest_version) > ::Semantic::Version.new(FluidCLI::VERSION)
634
+ end
635
+ end
636
+
637
+ # Returns file extension depending on OS
638
+ # since windows has multiple extensions, the default is .exe unless otherwise specified
639
+ #
640
+ # #### Parameters
641
+ # - ext: optional extension for windows file
642
+ #
643
+ # #### Returns
644
+ # - ext: string for file extension on windows
645
+ # : empty string otherwise
646
+ def executable_file_extension(ext = ".exe")
647
+ if windows?
648
+ ext
649
+ else
650
+ ""
651
+ end
652
+ end
653
+
654
+ # Uses bundle to grab the version of a gem
655
+ #
656
+ # #### Parameters
657
+ # - gem: the name of the gem to check
658
+ #
659
+ # #### Returns
660
+ # - version: a Semantic::Version object with the gem version
661
+ def ruby_gem_version(gem)
662
+ version = Bundler.load.specs.find { |s| s.name == gem }.version
663
+ ::Semantic::Version.new(version.to_s)
664
+ end
665
+
666
+ private
667
+
668
+ def ctx_path(fname)
669
+ require "pathname"
670
+ if Pathname.new(fname).absolute?
671
+ fname
672
+ else
673
+ File.join(root, fname)
674
+ end
675
+ end
676
+
677
+ def retrieve_latest_gem_version
678
+ response = Net::HTTP.get_response(GEM_LATEST_URI)
679
+ latest = JSON.parse(response.body)
680
+ FluidCLI::Config.set(VERSION_CHECK_SECTION, LATEST_VERSION_FIELD, latest["version"])
681
+ rescue
682
+ nil
683
+ ensure
684
+ FluidCLI::Config.set(VERSION_CHECK_SECTION, LAST_CHECKED_AT_FIELD, Time.now.to_i)
685
+ end
686
+
687
+ def time_of_last_check
688
+ (val = FluidCLI::Config.get(VERSION_CHECK_SECTION, LAST_CHECKED_AT_FIELD)) ? val.to_i : 0
689
+ end
690
+ end
691
+ end