diff --git a/Gemfile b/Gemfile index 40171e5..b1e7752 100644 --- a/Gemfile +++ b/Gemfile @@ -6,10 +6,11 @@ gem 'puma' gem 'bcrypt' gem 'faker' -flipper_version = '~> 1.2.2' +flipper_version = { git: "https://github.com/flippercloud/flipper", ref: "ef9a631858c582b53b6d0ab7bcc557e0c477a685" } gem 'flipper-cloud', flipper_version gem 'flipper-ui', flipper_version gem 'flipper-active_record', flipper_version +gem 'ansi-to-html' group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index c19e14f..d8eaa1c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,23 @@ +GIT + remote: https://github.com/flippercloud/flipper + revision: ef9a631858c582b53b6d0ab7bcc557e0c477a685 + ref: ef9a631858c582b53b6d0ab7bcc557e0c477a685 + specs: + flipper (1.2.2) + concurrent-ruby (< 2) + flipper-active_record (1.2.2) + activerecord (>= 4.2, < 8) + flipper (~> 1.2.2) + flipper-cloud (1.2.2) + flipper (~> 1.2.2) + flipper-ui (1.2.2) + erubi (>= 1.0.0, < 2.0.0) + flipper (~> 1.2.2) + rack (>= 1.4, < 4) + rack-protection (>= 1.5.3, < 5.0.0) + rack-session (>= 1.0.2, < 3.0.0) + sanitize (< 7) + GEM remote: https://rubygems.org/ specs: @@ -77,6 +97,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) + ansi-to-html (0.0.3) base64 (0.2.0) bcrypt (3.1.20) bigdecimal (3.1.6) @@ -108,19 +129,6 @@ GEM faker (3.2.3) i18n (>= 1.8.11, < 2) ffi (1.16.3) - flipper (1.2.2) - concurrent-ruby (< 2) - flipper-active_record (1.2.2) - activerecord (>= 4.2, < 8) - flipper (~> 1.2.2) - flipper-cloud (1.2.2) - flipper (~> 1.2.2) - flipper-ui (1.2.2) - erubi (>= 1.0.0, < 2.0.0) - flipper (~> 1.2.2) - rack (>= 1.4, < 4) - rack-protection (>= 1.5.3, <= 4.0.0) - sanitize (< 7) globalid (1.2.1) activesupport (>= 6.1) hashdiff (1.1.0) @@ -264,14 +272,15 @@ PLATFORMS x86_64-linux DEPENDENCIES + ansi-to-html bcrypt byebug capybara dotenv-rails faker - flipper-active_record (~> 1.2.2) - flipper-cloud (~> 1.2.2) - flipper-ui (~> 1.2.2) + flipper-active_record! + flipper-cloud! + flipper-ui! listen puma rails diff --git a/app/controllers/cli_controller.rb b/app/controllers/cli_controller.rb new file mode 100644 index 0000000..9987680 --- /dev/null +++ b/app/controllers/cli_controller.rb @@ -0,0 +1,6 @@ +class CliController < ApplicationController + def execute + @status, @output = WebCli.run(params[:prompt]) + render layout: false + end +end diff --git a/app/models/web_cli.rb b/app/models/web_cli.rb new file mode 100644 index 0000000..4b53203 --- /dev/null +++ b/app/models/web_cli.rb @@ -0,0 +1,28 @@ +require 'flipper/cli' + +class WebCli < Flipper::CLI + def self.run(input) + output = StringIO.new + + # Prentend this a TTY so we get colorization + def output.tty? + true + end + + status = new(stdout: output, stderr: output).run(Shellwords.split(input.to_s)) + + [status, output.string] + end + + # Override to not exit and return default status of 0 + def run(args) + super + 0 + rescue SystemExit => e + e.status + end + + def load_environment! + # already loaded, so no need + end +end diff --git a/app/views/cli/execute.html.erb b/app/views/cli/execute.html.erb new file mode 100644 index 0000000..621b811 --- /dev/null +++ b/app/views/cli/execute.html.erb @@ -0,0 +1,2 @@ +$ flipper <%= params[:prompt] %> +<%=raw Ansi::To::Html.new(h(@output)).to_html(:xterm) %> diff --git a/app/views/cli/show.html.erb b/app/views/cli/show.html.erb new file mode 100644 index 0000000..8a4d362 --- /dev/null +++ b/app/views/cli/show.html.erb @@ -0,0 +1,50 @@ + + +<% content_for :footer do %> + <%= page_footer(__FILE__) %> +<% end %> + + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cbe939b..f85e5cc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -42,13 +42,15 @@
-
+
<%= yield %>
- + <% if content_for?(:aside) %> + + <% end %>
diff --git a/app/views/shared/_page_footer.html.erb b/app/views/shared/_page_footer.html.erb index 53abcd3..c5d81a8 100644 --- a/app/views/shared/_page_footer.html.erb +++ b/app/views/shared/_page_footer.html.erb @@ -1,10 +1,15 @@ \ No newline at end of file + diff --git a/config/routes.rb b/config/routes.rb index 22d979c..9ffae38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,8 @@ get 'example/index', as: :examples get 'example/:slug', to: "example#show", as: :example + get "cli", to: "cli#show", as: :cli + post "cli", to: "cli#execute" get 'connect/:token', to: "cloud#connect", as: :cloud_connect