shopify-cli 1.4.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +2 -2
  3. data/.github/CONTRIBUTING.md +9 -1
  4. data/.github/PULL_REQUEST_TEMPLATE.md +3 -2
  5. data/.github/workflows/release.yml +0 -1
  6. data/.github/workflows/triage.yml +22 -0
  7. data/.rubocop.yml +21 -7
  8. data/.rubocop_todo.yml +2 -15
  9. data/.travis.yml +1 -1
  10. data/CHANGELOG.md +28 -0
  11. data/Gemfile +12 -11
  12. data/Gemfile.lock +17 -14
  13. data/README.md +39 -7
  14. data/RELEASING.md +5 -13
  15. data/Rakefile +32 -28
  16. data/bin/load_shopify.rb +6 -6
  17. data/bin/shopify +2 -2
  18. data/dev.yml +2 -2
  19. data/docs/_config.yml +1 -18
  20. data/docs/app/node/commands/index.md +2 -80
  21. data/docs/app/node/index.md +2 -33
  22. data/docs/app/rails/commands/index.md +2 -78
  23. data/docs/app/rails/index.md +2 -34
  24. data/docs/core/index.md +2 -84
  25. data/docs/getting-started/index.md +2 -25
  26. data/docs/getting-started/install/index.md +1 -118
  27. data/docs/getting-started/migrate/index.md +2 -94
  28. data/docs/getting-started/uninstall/index.md +2 -35
  29. data/docs/getting-started/upgrade/index.md +2 -39
  30. data/docs/help/start-app/index.md +2 -4
  31. data/docs/index.md +2 -24
  32. data/ext/shopify-cli/extconf.rb +7 -7
  33. data/install.sh +1 -1
  34. data/lib/docgen/markdown.rb +12 -12
  35. data/lib/graphql/fetch_specifications.graphql +14 -0
  36. data/lib/{project_types/extension/graphql → graphql}/get_app_by_api_key.graphql +0 -0
  37. data/lib/project_types/extension/cli.rb +54 -47
  38. data/lib/project_types/extension/commands/build.rb +3 -3
  39. data/lib/project_types/extension/commands/create.rb +17 -10
  40. data/lib/project_types/extension/commands/extension_command.rb +12 -5
  41. data/lib/project_types/extension/commands/push.rb +8 -8
  42. data/lib/project_types/extension/commands/register.rb +19 -30
  43. data/lib/project_types/extension/commands/serve.rb +31 -3
  44. data/lib/project_types/extension/commands/tunnel.rb +12 -12
  45. data/lib/project_types/extension/extension_project.rb +8 -4
  46. data/lib/project_types/extension/extension_project_keys.rb +4 -4
  47. data/lib/project_types/extension/features/argo.rb +117 -0
  48. data/lib/project_types/extension/features/argo_config.rb +5 -5
  49. data/lib/project_types/extension/features/argo_dependencies.rb +5 -5
  50. data/lib/project_types/extension/features/argo_setup.rb +2 -2
  51. data/lib/project_types/extension/features/argo_setup_steps.rb +4 -4
  52. data/lib/project_types/extension/forms/create.rb +28 -34
  53. data/lib/project_types/extension/forms/questions/ask_app.rb +53 -0
  54. data/lib/project_types/extension/forms/questions/ask_name.rb +40 -0
  55. data/lib/project_types/extension/forms/questions/ask_type.rb +47 -0
  56. data/lib/project_types/extension/messages/messages.rb +55 -52
  57. data/lib/project_types/extension/models/lazy_specification_handler.rb +12 -0
  58. data/lib/project_types/extension/models/specification.rb +37 -0
  59. data/lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb +19 -0
  60. data/lib/project_types/extension/models/specification_handlers/default.rb +67 -0
  61. data/lib/project_types/extension/models/specifications.rb +88 -0
  62. data/lib/project_types/extension/tasks/configure_features.rb +52 -0
  63. data/lib/project_types/extension/tasks/converters/app_converter.rb +6 -6
  64. data/lib/project_types/extension/tasks/converters/registration_converter.rb +6 -6
  65. data/lib/project_types/extension/tasks/converters/validation_error_converter.rb +4 -4
  66. data/lib/project_types/extension/tasks/converters/version_converter.rb +7 -7
  67. data/lib/project_types/extension/tasks/create_extension.rb +4 -4
  68. data/lib/project_types/extension/tasks/fetch_specifications.rb +18 -0
  69. data/lib/project_types/extension/tasks/get_app.rb +4 -4
  70. data/lib/project_types/extension/tasks/get_apps.rb +3 -3
  71. data/lib/project_types/extension/tasks/update_draft.rb +4 -4
  72. data/lib/project_types/extension/tasks/user_errors.rb +4 -4
  73. data/lib/project_types/node/cli.rb +19 -16
  74. data/lib/project_types/node/commands/connect.rb +15 -0
  75. data/lib/project_types/node/commands/create.rb +44 -41
  76. data/lib/project_types/node/commands/deploy.rb +4 -4
  77. data/lib/project_types/node/commands/deploy/heroku.rb +24 -24
  78. data/lib/project_types/node/commands/generate.rb +9 -18
  79. data/lib/project_types/node/commands/open.rb +2 -2
  80. data/lib/project_types/node/commands/populate.rb +6 -6
  81. data/lib/project_types/node/commands/populate/customer.rb +5 -5
  82. data/lib/project_types/node/commands/populate/draft_order.rb +5 -5
  83. data/lib/project_types/node/commands/populate/product.rb +5 -5
  84. data/lib/project_types/node/commands/serve.rb +9 -9
  85. data/lib/project_types/node/commands/tunnel.rb +7 -7
  86. data/lib/project_types/node/forms/create.rb +17 -8
  87. data/lib/project_types/node/messages/messages.rb +20 -53
  88. data/lib/project_types/rails/cli.rb +21 -18
  89. data/lib/project_types/rails/commands/connect.rb +15 -0
  90. data/lib/project_types/rails/commands/create.rb +58 -57
  91. data/lib/project_types/rails/commands/deploy.rb +4 -4
  92. data/lib/project_types/rails/commands/deploy/heroku.rb +30 -30
  93. data/lib/project_types/rails/commands/generate.rb +7 -7
  94. data/lib/project_types/rails/commands/generate/webhook.rb +6 -6
  95. data/lib/project_types/rails/commands/open.rb +2 -2
  96. data/lib/project_types/rails/commands/populate.rb +6 -6
  97. data/lib/project_types/rails/commands/populate/customer.rb +5 -5
  98. data/lib/project_types/rails/commands/populate/draft_order.rb +5 -5
  99. data/lib/project_types/rails/commands/populate/product.rb +5 -5
  100. data/lib/project_types/rails/commands/serve.rb +11 -11
  101. data/lib/project_types/rails/commands/tunnel.rb +7 -7
  102. data/lib/project_types/rails/forms/create.rb +35 -25
  103. data/lib/project_types/rails/gem.rb +24 -24
  104. data/lib/project_types/rails/messages/messages.rb +13 -9
  105. data/lib/project_types/rails/ruby.rb +2 -2
  106. data/lib/project_types/script/cli.rb +44 -38
  107. data/lib/project_types/script/commands/create.rb +15 -10
  108. data/lib/project_types/script/commands/disable.rb +3 -3
  109. data/lib/project_types/script/commands/enable.rb +19 -9
  110. data/lib/project_types/script/commands/push.rb +10 -17
  111. data/lib/project_types/script/config/extension_points.yml +30 -12
  112. data/lib/project_types/script/errors.rb +22 -0
  113. data/lib/project_types/script/forms/create.rb +29 -5
  114. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +12 -1
  115. data/lib/project_types/script/layers/application/build_script.rb +19 -19
  116. data/lib/project_types/script/layers/application/create_script.rb +45 -12
  117. data/lib/project_types/script/layers/application/disable_script.rb +2 -2
  118. data/lib/project_types/script/layers/application/enable_script.rb +2 -2
  119. data/lib/project_types/script/layers/application/extension_points.rb +24 -0
  120. data/lib/project_types/script/layers/application/project_dependencies.rb +4 -4
  121. data/lib/project_types/script/layers/application/push_script.rb +15 -18
  122. data/lib/project_types/script/layers/domain/config_ui.rb +16 -0
  123. data/lib/project_types/script/layers/domain/errors.rb +23 -0
  124. data/lib/project_types/script/layers/domain/extension_point.rb +67 -7
  125. data/lib/project_types/script/layers/domain/metadata.rb +55 -0
  126. data/lib/project_types/script/layers/domain/push_package.rb +29 -6
  127. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +45 -55
  128. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +41 -45
  129. data/lib/project_types/script/layers/infrastructure/config_ui_repository.rb +46 -0
  130. data/lib/project_types/script/layers/infrastructure/errors.rb +32 -5
  131. data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +12 -6
  132. data/lib/project_types/script/layers/infrastructure/project_creator.rb +2 -1
  133. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +20 -13
  134. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +72 -0
  135. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +59 -0
  136. data/lib/project_types/script/layers/infrastructure/script_service.rb +39 -17
  137. data/lib/project_types/script/layers/infrastructure/task_runner.rb +4 -3
  138. data/lib/project_types/script/messages/messages.rb +76 -10
  139. data/lib/project_types/script/script_project.rb +26 -16
  140. data/lib/project_types/script/ui/error_handler.rb +135 -50
  141. data/lib/project_types/script/ui/printing_spinner.rb +1 -1
  142. data/lib/project_types/script/ui/strict_spinner.rb +1 -1
  143. data/lib/project_types/theme/cli.rb +40 -0
  144. data/lib/project_types/theme/commands/connect.rb +54 -0
  145. data/lib/project_types/theme/commands/create.rb +48 -0
  146. data/lib/project_types/theme/commands/deploy.rb +38 -0
  147. data/lib/project_types/theme/commands/generate.rb +20 -0
  148. data/lib/project_types/theme/commands/generate/env.rb +79 -0
  149. data/lib/project_types/theme/commands/push.rb +55 -0
  150. data/lib/project_types/theme/commands/serve.rb +31 -0
  151. data/lib/project_types/theme/forms/connect.rb +34 -0
  152. data/lib/project_types/theme/forms/create.rb +22 -0
  153. data/lib/project_types/theme/messages/messages.rb +147 -0
  154. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +78 -0
  155. data/lib/project_types/theme/themekit.rb +113 -0
  156. data/lib/rubygems_plugin.rb +3 -3
  157. data/lib/shopify-cli/admin_api.rb +52 -12
  158. data/lib/shopify-cli/admin_api/populate_resource_command.rb +17 -17
  159. data/lib/shopify-cli/admin_api/schema.rb +3 -3
  160. data/lib/shopify-cli/api.rb +36 -31
  161. data/lib/shopify-cli/command.rb +1 -1
  162. data/lib/shopify-cli/commands.rb +9 -9
  163. data/lib/shopify-cli/commands/config.rb +28 -28
  164. data/lib/shopify-cli/commands/connect.rb +35 -18
  165. data/lib/shopify-cli/commands/create.rb +5 -5
  166. data/lib/shopify-cli/commands/help.rb +6 -6
  167. data/lib/shopify-cli/commands/logout.rb +3 -3
  168. data/lib/shopify-cli/commands/system.rb +33 -33
  169. data/lib/shopify-cli/commands/version.rb +2 -2
  170. data/lib/shopify-cli/context.rb +43 -22
  171. data/lib/shopify-cli/core.rb +4 -4
  172. data/lib/shopify-cli/core/entry_point.rb +5 -5
  173. data/lib/shopify-cli/core/executor.rb +1 -1
  174. data/lib/shopify-cli/core/help_resolver.rb +2 -2
  175. data/lib/shopify-cli/core/monorail.rb +17 -16
  176. data/lib/shopify-cli/db.rb +2 -2
  177. data/lib/shopify-cli/feature.rb +1 -3
  178. data/lib/shopify-cli/form.rb +1 -1
  179. data/lib/shopify-cli/git.rb +17 -17
  180. data/lib/shopify-cli/helpers.rb +1 -1
  181. data/lib/shopify-cli/helpers/haikunator.rb +1 -1
  182. data/lib/shopify-cli/heroku.rb +28 -28
  183. data/lib/shopify-cli/http_request.rb +21 -9
  184. data/lib/shopify-cli/js_deps.rb +13 -13
  185. data/lib/shopify-cli/js_system.rb +5 -5
  186. data/lib/shopify-cli/lazy_delegator.rb +55 -0
  187. data/lib/shopify-cli/messages/messages.rb +21 -10
  188. data/lib/shopify-cli/method_object.rb +104 -0
  189. data/lib/shopify-cli/oauth.rb +25 -25
  190. data/lib/shopify-cli/oauth/servlet.rb +9 -9
  191. data/lib/shopify-cli/options.rb +3 -3
  192. data/lib/shopify-cli/packager.rb +24 -24
  193. data/lib/shopify-cli/partners_api.rb +38 -16
  194. data/lib/shopify-cli/partners_api/organizations.rb +10 -10
  195. data/lib/shopify-cli/process_supervision.rb +8 -8
  196. data/lib/shopify-cli/project.rb +27 -23
  197. data/lib/shopify-cli/project_type.rb +21 -5
  198. data/lib/shopify-cli/resolve_constant.rb +25 -0
  199. data/lib/shopify-cli/resources.rb +1 -1
  200. data/lib/shopify-cli/resources/env_file.rb +9 -9
  201. data/lib/shopify-cli/result.rb +432 -0
  202. data/lib/shopify-cli/shopifolk.rb +35 -18
  203. data/lib/shopify-cli/sub_command.rb +1 -1
  204. data/lib/shopify-cli/task.rb +9 -1
  205. data/lib/shopify-cli/tasks.rb +7 -7
  206. data/lib/shopify-cli/tasks/create_api_client.rb +13 -4
  207. data/lib/shopify-cli/tasks/ensure_dev_store.rb +12 -12
  208. data/lib/shopify-cli/tasks/ensure_env.rb +18 -15
  209. data/lib/shopify-cli/tasks/ensure_loopback_url.rb +4 -4
  210. data/lib/shopify-cli/tasks/select_org_and_shop.rb +28 -24
  211. data/lib/shopify-cli/tasks/update_dashboard_urls.rb +10 -10
  212. data/lib/shopify-cli/transform_data_structure.rb +86 -0
  213. data/lib/shopify-cli/tunnel.rb +36 -30
  214. data/lib/shopify-cli/version.rb +1 -1
  215. data/lib/shopify_cli.rb +57 -52
  216. data/shopify-cli.gemspec +6 -6
  217. data/shopify.fish +1 -1
  218. data/shopify.sh +1 -1
  219. data/vendor/deps/cli-kit/REVISION +1 -1
  220. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +2 -2
  221. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +3 -3
  222. data/vendor/deps/cli-ui/REVISION +1 -1
  223. data/vendor/deps/cli-ui/lib/cli/ui.rb +26 -22
  224. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +4 -6
  225. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -3
  226. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +8 -9
  227. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -1
  228. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +1 -0
  229. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +15 -3
  230. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +4 -11
  231. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -5
  232. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +10 -10
  233. data/vendor/deps/cli-ui/lib/cli/ui/version.rb +1 -1
  234. data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +56 -0
  235. data/vendor/deps/webrick/.gitignore +9 -0
  236. data/vendor/deps/webrick/Gemfile +3 -0
  237. data/vendor/deps/webrick/LICENSE.txt +22 -0
  238. data/vendor/deps/webrick/README.md +61 -0
  239. data/vendor/deps/webrick/Rakefile +10 -0
  240. data/vendor/deps/webrick/lib/webrick.rb +232 -0
  241. data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
  242. data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
  243. data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
  244. data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
  245. data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
  246. data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
  247. data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
  248. data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
  249. data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
  250. data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
  251. data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
  252. data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
  253. data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
  254. data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
  255. data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
  256. data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
  257. data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
  258. data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
  259. data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
  260. data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
  261. data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
  262. data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  263. data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
  264. data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
  265. data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
  266. data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
  267. data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
  268. data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
  269. data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
  270. data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
  271. data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
  272. data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
  273. data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
  274. data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
  275. data/vendor/deps/webrick/webrick.gemspec +74 -0
  276. data/vendor/gen/template/bin/update-deps +9 -9
  277. metadata +83 -29
  278. data/docs/Gemfile +0 -5
  279. data/docs/Gemfile.lock +0 -258
  280. data/docs/_data/nav.yml +0 -35
  281. data/docs/_includes/footer.html +0 -15
  282. data/docs/_includes/head.html +0 -19
  283. data/docs/_includes/sidebar_nav.html +0 -22
  284. data/docs/_includes/toc.html +0 -112
  285. data/docs/_layouts/default.html +0 -79
  286. data/docs/css/docs.css +0 -157
  287. data/docs/images/header.png +0 -0
  288. data/docs/installing-ruby.md +0 -28
  289. data/lib/project_types/extension/features/argo/admin.rb +0 -20
  290. data/lib/project_types/extension/features/argo/base.rb +0 -129
  291. data/lib/project_types/extension/features/argo/checkout.rb +0 -20
  292. data/lib/project_types/extension/forms/register.rb +0 -47
  293. data/lib/project_types/extension/models/type.rb +0 -81
  294. data/lib/project_types/extension/models/types/checkout_post_purchase.rb +0 -23
  295. data/lib/project_types/extension/models/types/product_subscription.rb +0 -24
  296. data/lib/project_types/node/commands/generate/billing.rb +0 -39
  297. data/lib/project_types/node/commands/generate/page.rb +0 -59
  298. data/lib/project_types/node/commands/generate/webhook.rb +0 -37
  299. data/lib/project_types/script/layers/domain/script.rb +0 -18
  300. data/lib/project_types/script/layers/infrastructure/assemblyscript_tsconfig.rb +0 -38
  301. data/lib/project_types/script/layers/infrastructure/script_repository.rb +0 -59
  302. data/lib/project_types/script/templates/ts/as-pect.config.js +0 -27
  303. data/lib/project_types/script/templates/ts/as-pect.d.ts +0 -1
@@ -21,6 +21,8 @@ module CLI
21
21
  when 0x200d # zero-width joiner
22
22
  zwj = true
23
23
  acc
24
+ when "\n"
25
+ acc
24
26
  else
25
27
  acc + 1
26
28
  end
@@ -138,17 +140,13 @@ module CLI
138
140
  # Move to the next line
139
141
  #
140
142
  def self.next_line
141
- cmd = cursor_down + control('1', 'G')
142
- cmd += control('1', 'D') if CLI::UI::OS.current.shift_cursor_on_line_reset?
143
- cmd
143
+ cursor_down + cursor_horizontal_absolute
144
144
  end
145
145
 
146
146
  # Move to the previous line
147
147
  #
148
148
  def self.previous_line
149
- cmd = cursor_up + control('1', 'G')
150
- cmd += control('1', 'D') if CLI::UI::OS.current.shift_cursor_on_line_reset?
151
- cmd
149
+ cursor_up + cursor_horizontal_absolute
152
150
  end
153
151
 
154
152
  def self.clear_to_end_of_line
@@ -90,7 +90,7 @@ module CLI
90
90
 
91
91
  t_start = Time.now
92
92
  CLI::UI.raw do
93
- print prefix.chop
93
+ print(prefix.chop)
94
94
  puts frame_style.open(text, color: color)
95
95
  end
96
96
  FrameStack.push(color: color, style: frame_style)
@@ -153,7 +153,7 @@ module CLI
153
153
  frame_style = CLI::UI.resolve_style(frame_style) || fs_item.frame_style
154
154
 
155
155
  CLI::UI.raw do
156
- print prefix.chop
156
+ print(prefix.chop)
157
157
  puts frame_style.divider(text, color: color)
158
158
  end
159
159
 
@@ -197,7 +197,7 @@ module CLI
197
197
  end
198
198
 
199
199
  CLI::UI.raw do
200
- print prefix.chop
200
+ print(prefix.chop)
201
201
  puts frame_style.close(text, color: color, **kwargs)
202
202
  end
203
203
  end
@@ -5,13 +5,12 @@ module CLI
5
5
  COLOR_ENVVAR = 'CLI_FRAME_STACK'
6
6
  STYLE_ENVVAR = 'CLI_STYLE_STACK'
7
7
 
8
- StackItem = Struct.new(:color_name, :style_name) do
9
- def color
10
- @color ||= CLI::UI.resolve_color(color_name)
11
- end
8
+ class StackItem
9
+ attr_reader :color, :frame_style
12
10
 
13
- def frame_style
14
- @frame_style ||= CLI::UI.resolve_style(style_name)
11
+ def initialize(color_name, style_name)
12
+ @color = CLI::UI.resolve_color(color_name)
13
+ @frame_style = CLI::UI.resolve_style(style_name)
15
14
  end
16
15
  end
17
16
 
@@ -55,7 +54,7 @@ module CLI
55
54
  end
56
55
  end
57
56
 
58
- item ||= StackItem.new(color.name, style.name)
57
+ item ||= StackItem.new(color, style)
59
58
 
60
59
  curr = items
61
60
  curr << item
@@ -85,8 +84,8 @@ module CLI
85
84
  styles = []
86
85
 
87
86
  items.each do |item|
88
- colors << item.color_name
89
- styles << item.style_name
87
+ colors << item.color.name
88
+ styles << item.frame_style.name
90
89
  end
91
90
 
92
91
  ENV[COLOR_ENVVAR] = colors.join(':')
@@ -39,7 +39,7 @@ module CLI
39
39
  def message
40
40
  keys = FrameStyle.loaded_styles.map(&:inspect).join(',')
41
41
  "invalid frame style: #{@name.inspect}" \
42
- "-- must be one of CLI::UI::Frame::FrameStyle.loaded_styles " \
42
+ " -- must be one of CLI::UI::Frame::FrameStyle.loaded_styles " \
43
43
  "(#{keys})"
44
44
  end
45
45
  end
@@ -57,6 +57,7 @@ module CLI
57
57
  BUG = new('b', 0x1f41b, '!', Color::WHITE) # Bug emoji (🐛)
58
58
  CHEVRON = new('>', 0xbb, '»', Color::YELLOW) # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (»)
59
59
  HOURGLASS = new('H', [0x231b, 0xfe0e], 'H', Color::BLUE) # HOURGLASS + VARIATION SELECTOR 15 (⌛︎)
60
+ WARNING = new('!', [0x26a0, 0xfe0f], '!', Color::YELLOW) # WARNING SIGN + VARIATION SELECTOR 16 (⚠️ )
60
61
 
61
62
  # Looks up a glyph by name
62
63
  #
@@ -18,6 +18,7 @@ module CLI
18
18
  # * +:encoding+ - Force the output to be in a certain encoding. Defaults to UTF-8.
19
19
  # * +:format+ - Whether to format the string using CLI::UI.fmt. Defaults to true.
20
20
  # * +:graceful+ - Whether to gracefully ignore common I/O errors. Defaults to true.
21
+ # * +:wrap+ - Whether to wrap text at word boundaries to terminal width. Defaults to true.
21
22
  #
22
23
  # ==== Returns
23
24
  # Returns whether the message was successfully printed,
@@ -25,11 +26,22 @@ module CLI
25
26
  #
26
27
  # ==== Example
27
28
  #
28
- # CLI::UI::Printer.puts('{x} Ouch', stream: $stderr, color: :red)
29
- #
30
- def self.puts(msg, frame_color: nil, to: $stdout, encoding: Encoding::UTF_8, format: true, graceful: true)
29
+ # CLI::UI::Printer.puts('{{x}} Ouch', to: $stderr)
30
+ #
31
+ def self.puts(
32
+ msg,
33
+ frame_color:
34
+ nil,
35
+ to:
36
+ $stdout,
37
+ encoding: Encoding::UTF_8,
38
+ format: true,
39
+ graceful: true,
40
+ wrap: true
41
+ )
31
42
  msg = (+msg).force_encoding(encoding) if encoding
32
43
  msg = CLI::UI.fmt(msg) if format
44
+ msg = CLI::UI.wrap(msg) if wrap
33
45
 
34
46
  if frame_color
35
47
  CLI::UI::Frame.with_frame_color_override(frame_color) { to.puts(msg) }
@@ -334,22 +334,15 @@ module CLI
334
334
  end
335
335
 
336
336
  def read_char
337
- raw_tty! do
338
- getc = $stdin.getc
339
- getc ? getc.chr : :timeout
337
+ if $stdin.tty? && !ENV['TEST']
338
+ $stdin.getch # raw mode for tty
339
+ else
340
+ $stdin.getc
340
341
  end
341
342
  rescue IOError
342
343
  "\e"
343
344
  end
344
345
 
345
- def raw_tty!
346
- if ENV['TEST'] || !$stdin.tty?
347
- yield
348
- else
349
- $stdin.raw { yield }
350
- end
351
- end
352
-
353
346
  def presented_options(recalculate: false)
354
347
  return @presented_options unless recalculate
355
348
 
@@ -12,11 +12,9 @@ module CLI
12
12
 
13
13
  RUNES = CLI::UI::OS.current.supports_emoji? ? %w(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏).freeze : %w(\\ | / - \\ | / -).freeze
14
14
 
15
- begin
16
- colors = [CLI::UI::Color::CYAN.code] * (RUNES.size / 2).ceil +
17
- [CLI::UI::Color::MAGENTA.code] * (RUNES.size / 2).to_i
18
- GLYPHS = colors.zip(RUNES).map(&:join)
19
- end
15
+ colors = [CLI::UI::Color::CYAN.code] * (RUNES.size / 2).ceil +
16
+ [CLI::UI::Color::MAGENTA.code] * (RUNES.size / 2).to_i
17
+ GLYPHS = colors.zip(RUNES).map(&:join)
20
18
 
21
19
  class << self
22
20
  attr_accessor(:index)
@@ -23,17 +23,17 @@ module CLI
23
23
 
24
24
  def self.winsize
25
25
  @winsize ||= begin
26
- winsize = IO.console.winsize
27
- setup_winsize_trap
26
+ winsize = IO.console.winsize
27
+ setup_winsize_trap
28
28
 
29
- if winsize.any?(&:zero?)
30
- [DEFAULT_HEIGHT, DEFAULT_WIDTH]
31
- else
32
- winsize
33
- end
34
- rescue
35
- [DEFAULT_HEIGHT, DEFAULT_WIDTH]
36
- end
29
+ if winsize.any?(&:zero?)
30
+ [DEFAULT_HEIGHT, DEFAULT_WIDTH]
31
+ else
32
+ winsize
33
+ end
34
+ rescue
35
+ [DEFAULT_HEIGHT, DEFAULT_WIDTH]
36
+ end
37
37
  end
38
38
 
39
39
  def self.setup_winsize_trap
@@ -1,5 +1,5 @@
1
1
  module CLI
2
2
  module UI
3
- VERSION = "1.3.0"
3
+ VERSION = "1.4.0"
4
4
  end
5
5
  end
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ require 'cli/ui'
3
+ require 'cli/ui/frame/frame_stack'
4
+ require 'cli/ui/frame/frame_style'
5
+
6
+ module CLI
7
+ module UI
8
+ class Wrap
9
+ def initialize(input)
10
+ @input = input
11
+ end
12
+
13
+ def wrap
14
+ max_width = Terminal.width - Frame.prefix_width
15
+ width = 0
16
+ final = []
17
+ # Create an alternation of format codes of parameter lengths 1-20, since + and {1,n} not allowed in lookbehind
18
+ format_codes = (1..20).map { |n| /\x1b\[[\d;]{#{n}}m/ }.join('|')
19
+ codes = ''
20
+ @input.split(/(?=\s|\x1b\[[\d;]+m|\r)|(?<=\s|#{format_codes})/).each do |token|
21
+ case token
22
+ when '\x1B[0?m'
23
+ codes = ''
24
+ final << token
25
+ when /\x1b\[[\d;]+m/
26
+ codes += token # Track in use format codes so that they are resent after frame coloring
27
+ final << token
28
+ when "\n"
29
+ final << "\n#{codes}"
30
+ width = 0
31
+ when /\s/
32
+ token_width = ANSI.printing_width(token)
33
+ if width + token_width <= max_width
34
+ final << token
35
+ width += token_width
36
+ else
37
+ final << "\n#{codes}"
38
+ width = 0
39
+ end
40
+ else
41
+ token_width = ANSI.printing_width(token)
42
+ if width + token_width <= max_width
43
+ final << token
44
+ width += token_width
45
+ else
46
+ final << "\n#{codes}"
47
+ final << token
48
+ width = token_width
49
+ end
50
+ end
51
+ end
52
+ final.join
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
@@ -0,0 +1,61 @@
1
+ # Webrick
2
+
3
+ WEBrick is an HTTP server toolkit that can be configured as an HTTPS server, a proxy server, and a virtual-host server.
4
+
5
+ WEBrick features complete logging of both server operations and HTTP access.
6
+
7
+ WEBrick supports both basic and digest authentication in addition to algorithms not in RFC 2617.
8
+
9
+ A WEBrick server can be composed of multiple WEBrick servers or servlets to provide differing behavior on a per-host or per-path basis. WEBrick includes servlets for handling CGI scripts, ERB pages, Ruby blocks and directory listings.
10
+
11
+ WEBrick also includes tools for daemonizing a process and starting a process at a higher privilege level and dropping permissions.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'webrick'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install webrick
28
+
29
+ ## Usage
30
+
31
+ To create a new WEBrick::HTTPServer that will listen to connections on port 8000 and serve documents from the current user's public_html folder:
32
+
33
+ ```ruby
34
+ require 'webrick'
35
+
36
+ root = File.expand_path '~/public_html'
37
+ server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
38
+ ```
39
+
40
+ To run the server you will need to provide a suitable shutdown hook as
41
+ starting the server blocks the current thread:
42
+
43
+ ```ruby
44
+ trap 'INT' do server.shutdown end
45
+
46
+ server.start
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and Patch are welcome on https://bugs.ruby-lang.org/.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test" << "test/lib"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/test_*.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,232 @@
1
+ # frozen_string_literal: false
2
+ ##
3
+ # = WEB server toolkit.
4
+ #
5
+ # WEBrick is an HTTP server toolkit that can be configured as an HTTPS server,
6
+ # a proxy server, and a virtual-host server. WEBrick features complete
7
+ # logging of both server operations and HTTP access. WEBrick supports both
8
+ # basic and digest authentication in addition to algorithms not in RFC 2617.
9
+ #
10
+ # A WEBrick server can be composed of multiple WEBrick servers or servlets to
11
+ # provide differing behavior on a per-host or per-path basis. WEBrick
12
+ # includes servlets for handling CGI scripts, ERB pages, Ruby blocks and
13
+ # directory listings.
14
+ #
15
+ # WEBrick also includes tools for daemonizing a process and starting a process
16
+ # at a higher privilege level and dropping permissions.
17
+ #
18
+ # == Security
19
+ #
20
+ # *Warning:* WEBrick is not recommended for production. It only implements
21
+ # basic security checks.
22
+ #
23
+ # == Starting an HTTP server
24
+ #
25
+ # To create a new WEBrick::HTTPServer that will listen to connections on port
26
+ # 8000 and serve documents from the current user's public_html folder:
27
+ #
28
+ # require 'webrick'
29
+ #
30
+ # root = File.expand_path '~/public_html'
31
+ # server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
32
+ #
33
+ # To run the server you will need to provide a suitable shutdown hook as
34
+ # starting the server blocks the current thread:
35
+ #
36
+ # trap 'INT' do server.shutdown end
37
+ #
38
+ # server.start
39
+ #
40
+ # == Custom Behavior
41
+ #
42
+ # The easiest way to have a server perform custom operations is through
43
+ # WEBrick::HTTPServer#mount_proc. The block given will be called with a
44
+ # WEBrick::HTTPRequest with request info and a WEBrick::HTTPResponse which
45
+ # must be filled in appropriately:
46
+ #
47
+ # server.mount_proc '/' do |req, res|
48
+ # res.body = 'Hello, world!'
49
+ # end
50
+ #
51
+ # Remember that +server.mount_proc+ must precede +server.start+.
52
+ #
53
+ # == Servlets
54
+ #
55
+ # Advanced custom behavior can be obtained through mounting a subclass of
56
+ # WEBrick::HTTPServlet::AbstractServlet. Servlets provide more modularity
57
+ # when writing an HTTP server than mount_proc allows. Here is a simple
58
+ # servlet:
59
+ #
60
+ # class Simple < WEBrick::HTTPServlet::AbstractServlet
61
+ # def do_GET request, response
62
+ # status, content_type, body = do_stuff_with request
63
+ #
64
+ # response.status = 200
65
+ # response['Content-Type'] = 'text/plain'
66
+ # response.body = 'Hello, World!'
67
+ # end
68
+ # end
69
+ #
70
+ # To initialize the servlet you mount it on the server:
71
+ #
72
+ # server.mount '/simple', Simple
73
+ #
74
+ # See WEBrick::HTTPServlet::AbstractServlet for more details.
75
+ #
76
+ # == Virtual Hosts
77
+ #
78
+ # A server can act as a virtual host for multiple host names. After creating
79
+ # the listening host, additional hosts that do not listen can be created and
80
+ # attached as virtual hosts:
81
+ #
82
+ # server = WEBrick::HTTPServer.new # ...
83
+ #
84
+ # vhost = WEBrick::HTTPServer.new :ServerName => 'vhost.example',
85
+ # :DoNotListen => true, # ...
86
+ # vhost.mount '/', ...
87
+ #
88
+ # server.virtual_host vhost
89
+ #
90
+ # If no +:DocumentRoot+ is provided and no servlets or procs are mounted on the
91
+ # main server it will return 404 for all URLs.
92
+ #
93
+ # == HTTPS
94
+ #
95
+ # To create an HTTPS server you only need to enable SSL and provide an SSL
96
+ # certificate name:
97
+ #
98
+ # require 'webrick'
99
+ # require 'webrick/https'
100
+ #
101
+ # cert_name = [
102
+ # %w[CN localhost],
103
+ # ]
104
+ #
105
+ # server = WEBrick::HTTPServer.new(:Port => 8000,
106
+ # :SSLEnable => true,
107
+ # :SSLCertName => cert_name)
108
+ #
109
+ # This will start the server with a self-generated self-signed certificate.
110
+ # The certificate will be changed every time the server is restarted.
111
+ #
112
+ # To create a server with a pre-determined key and certificate you can provide
113
+ # them:
114
+ #
115
+ # require 'webrick'
116
+ # require 'webrick/https'
117
+ # require 'openssl'
118
+ #
119
+ # cert = OpenSSL::X509::Certificate.new File.read '/path/to/cert.pem'
120
+ # pkey = OpenSSL::PKey::RSA.new File.read '/path/to/pkey.pem'
121
+ #
122
+ # server = WEBrick::HTTPServer.new(:Port => 8000,
123
+ # :SSLEnable => true,
124
+ # :SSLCertificate => cert,
125
+ # :SSLPrivateKey => pkey)
126
+ #
127
+ # == Proxy Server
128
+ #
129
+ # WEBrick can act as a proxy server:
130
+ #
131
+ # require 'webrick'
132
+ # require 'webrick/httpproxy'
133
+ #
134
+ # proxy = WEBrick::HTTPProxyServer.new :Port => 8000
135
+ #
136
+ # trap 'INT' do proxy.shutdown end
137
+ #
138
+ # See WEBrick::HTTPProxy for further details including modifying proxied
139
+ # responses.
140
+ #
141
+ # == Basic and Digest authentication
142
+ #
143
+ # WEBrick provides both Basic and Digest authentication for regular and proxy
144
+ # servers. See WEBrick::HTTPAuth, WEBrick::HTTPAuth::BasicAuth and
145
+ # WEBrick::HTTPAuth::DigestAuth.
146
+ #
147
+ # == WEBrick as a daemonized Web Server
148
+ #
149
+ # WEBrick can be run as a daemonized server for small loads.
150
+ #
151
+ # === Daemonizing
152
+ #
153
+ # To start a WEBrick server as a daemon simple run WEBrick::Daemon.start
154
+ # before starting the server.
155
+ #
156
+ # === Dropping Permissions
157
+ #
158
+ # WEBrick can be started as one user to gain permission to bind to port 80 or
159
+ # 443 for serving HTTP or HTTPS traffic then can drop these permissions for
160
+ # regular operation. To listen on all interfaces for HTTP traffic:
161
+ #
162
+ # sockets = WEBrick::Utils.create_listeners nil, 80
163
+ #
164
+ # Then drop privileges:
165
+ #
166
+ # WEBrick::Utils.su 'www'
167
+ #
168
+ # Then create a server that does not listen by default:
169
+ #
170
+ # server = WEBrick::HTTPServer.new :DoNotListen => true, # ...
171
+ #
172
+ # Then overwrite the listening sockets with the port 80 sockets:
173
+ #
174
+ # server.listeners.replace sockets
175
+ #
176
+ # === Logging
177
+ #
178
+ # WEBrick can separately log server operations and end-user access. For
179
+ # server operations:
180
+ #
181
+ # log_file = File.open '/var/log/webrick.log', 'a+'
182
+ # log = WEBrick::Log.new log_file
183
+ #
184
+ # For user access logging:
185
+ #
186
+ # access_log = [
187
+ # [log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
188
+ # ]
189
+ #
190
+ # server = WEBrick::HTTPServer.new :Logger => log, :AccessLog => access_log
191
+ #
192
+ # See WEBrick::AccessLog for further log formats.
193
+ #
194
+ # === Log Rotation
195
+ #
196
+ # To rotate logs in WEBrick on a HUP signal (like syslogd can send), open the
197
+ # log file in 'a+' mode (as above) and trap 'HUP' to reopen the log file:
198
+ #
199
+ # trap 'HUP' do log_file.reopen '/path/to/webrick.log', 'a+'
200
+ #
201
+ # == Copyright
202
+ #
203
+ # Author: IPR -- Internet Programming with Ruby -- writers
204
+ #
205
+ # Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU
206
+ # Copyright (c) 2002 Internet Programming with Ruby writers. All rights
207
+ # reserved.
208
+ #--
209
+ # $IPR: webrick.rb,v 1.12 2002/10/01 17:16:31 gotoyuzo Exp $
210
+
211
+ module WEBrick
212
+ end
213
+
214
+ require 'webrick/compat.rb'
215
+
216
+ require 'webrick/version.rb'
217
+ require 'webrick/config.rb'
218
+ require 'webrick/log.rb'
219
+ require 'webrick/server.rb'
220
+ require_relative 'webrick/utils.rb'
221
+ require 'webrick/accesslog'
222
+
223
+ require 'webrick/htmlutils.rb'
224
+ require 'webrick/httputils.rb'
225
+ require 'webrick/cookie.rb'
226
+ require 'webrick/httpversion.rb'
227
+ require 'webrick/httpstatus.rb'
228
+ require 'webrick/httprequest.rb'
229
+ require 'webrick/httpresponse.rb'
230
+ require 'webrick/httpserver.rb'
231
+ require 'webrick/httpservlet.rb'
232
+ require 'webrick/httpauth.rb'