Sha256: 872f90b7828bc1b2b26fd9f32aec021164977f1458c1510a334d26fdd72a149c
Contents?: true
Size: 1.8 KB
Versions: 17
Compression:
Stored size: 1.8 KB
Contents
# frozen_string_literal: true require 'shopify_cli' module Extension module Commands class Tunnel < ExtensionCommand options do |parser, flags| parser.on('--port=PORT') { |port| flags[:port] = port } end AUTH_SUBCOMMAND = 'auth' START_SUBCOMMAND = 'start' STOP_SUBCOMMAND = 'stop' STATUS_SUBCOMMAND = 'status' DEFAULT_PORT = 39351 def call(args, _name) subcommand = args.shift case subcommand when AUTH_SUBCOMMAND then authorize(args) when START_SUBCOMMAND then ShopifyCli::Tunnel.start(@ctx, port: port) when STOP_SUBCOMMAND then ShopifyCli::Tunnel.stop(@ctx) when STATUS_SUBCOMMAND then status else @ctx.puts(self.class.help) end end def self.help ShopifyCli::Context.message('tunnel.help', ShopifyCli::TOOL_NAME) end def self.extended_help ShopifyCli::Context.message('tunnel.extended_help', ShopifyCli::TOOL_NAME, DEFAULT_PORT) end private def status tunnel_url = ShopifyCli::Tunnel.urls.first if tunnel_url.nil? @ctx.puts(@ctx.message('tunnel.no_tunnel_running')) else @ctx.puts(@ctx.message('tunnel.tunnel_running_at', tunnel_url)) end end def port return DEFAULT_PORT unless options.flags.key?(:port) port = options.flags[:port].to_i @ctx.abort(@ctx.message('tunnel.invalid_port', options.flags[:port])) unless port > 0 port end def authorize(args) token = args.shift if token.nil? @ctx.puts(@ctx.message('tunnel.missing_token')) @ctx.puts("#{self.class.help}\n#{self.class.extended_help}") else ShopifyCli::Tunnel.auth(@ctx, token) end end end end end
Version data entries
17 entries across 17 versions & 1 rubygems