From 577d01d7bca07310eb6d883aed4e974643a498a1 Mon Sep 17 00:00:00 2001 From: Piotr Murach Date: Sun, 8 Nov 2020 17:53:54 +0100 Subject: [PATCH] Change add command templates to use double-quoted strings --- lib/tty/commands/add.rb | 24 ++++---- lib/tty/templates/add/command.rb.tt | 14 ++--- lib/tty/templates/add/namespace.rb.tt | 8 +-- spec/integration/add_desc_args_spec.rb | 50 ++++++++-------- spec/integration/add_force_spec.rb | 4 +- spec/integration/add_namespaced_spec.rb | 30 +++++----- spec/integration/add_spec.rb | 76 ++++++++++++------------- spec/integration/add_subcommand_spec.rb | 19 ++++--- 8 files changed, 113 insertions(+), 112 deletions(-) diff --git a/lib/tty/commands/add.rb b/lib/tty/commands/add.rb index 9f0e0fc..c25ead3 100644 --- a/lib/tty/commands/add.rb +++ b/lib/tty/commands/add.rb @@ -180,14 +180,14 @@ def register_subcmd_matches def cmd_template <<-EOS -#{app_indent}#{cmd_indent}desc '#{cmd_name_underscored}#{cmd_desc_args}', '#{cmd_desc}' -#{app_indent}#{cmd_indent}method_option :help, aliases: '-h', type: :boolean, -#{app_indent}#{cmd_indent} desc: 'Display usage information' +#{app_indent}#{cmd_indent}desc "#{cmd_name_underscored}#{cmd_desc_args}", "#{cmd_desc}" +#{app_indent}#{cmd_indent}method_option :help, aliases: "-h", type: :boolean, +#{app_indent}#{cmd_indent} desc: "Display usage information" #{app_indent}#{cmd_indent}def #{cmd_name_underscored}(#{cmd_args.join(', ')}) #{app_indent}#{cmd_indent} if options[:help] -#{app_indent}#{cmd_indent} invoke :help, ['#{cmd_name_underscored}'] +#{app_indent}#{cmd_indent} invoke :help, ["#{cmd_name_underscored}"] #{app_indent}#{cmd_indent} else -#{app_indent}#{cmd_indent} require_relative 'commands/#{cmd_name_path}' +#{app_indent}#{cmd_indent} require_relative "commands/#{cmd_name_path}" #{app_indent}#{cmd_indent} #{cmd_object_parts.join('::')}.new(#{cmd_options.join(', ')}).execute #{app_indent}#{cmd_indent} end #{app_indent}#{cmd_indent}end @@ -196,21 +196,21 @@ def cmd_template def register_subcmd_template <<-EOS -#{app_indent} require_relative 'commands/#{cmd_name_path}' -#{app_indent} register #{cmd_object_parts[0..-2].join('::')}, '#{cmd_name_underscored}', '#{cmd_name_underscored} [SUBCOMMAND]', '#{cmd_desc}' +#{app_indent} require_relative "commands/#{cmd_name_path}" +#{app_indent} register #{cmd_object_parts[0..-2].join('::')}, "#{cmd_name_underscored}", "#{cmd_name_underscored} [SUBCOMMAND]", "#{cmd_desc}" EOS end def subcmd_template <<-EOS -#{app_indent}#{cmd_indent}desc '#{subcmd_name_underscored}#{cmd_desc_args}', '#{cmd_desc}' -#{app_indent}#{cmd_indent}method_option :help, aliases: '-h', type: :boolean, -#{app_indent}#{cmd_indent} desc: 'Display usage information' +#{app_indent}#{cmd_indent}desc "#{subcmd_name_underscored}#{cmd_desc_args}", "#{cmd_desc}" +#{app_indent}#{cmd_indent}method_option :help, aliases: "-h", type: :boolean, +#{app_indent}#{cmd_indent} desc: "Display usage information" #{app_indent}#{cmd_indent}def #{subcmd_name_underscored}(#{cmd_args.join(', ')}) #{app_indent}#{cmd_indent} if options[:help] -#{app_indent}#{cmd_indent} invoke :help, ['#{subcmd_name_underscored}'] +#{app_indent}#{cmd_indent} invoke :help, ["#{subcmd_name_underscored}"] #{app_indent}#{cmd_indent} else -#{app_indent}#{cmd_indent} require_relative '#{cmd_name_path}/#{subcmd_name_path}' +#{app_indent}#{cmd_indent} require_relative "#{cmd_name_path}/#{subcmd_name_path}" #{app_indent}#{cmd_indent} #{cmd_object_parts.join('::')}.new(#{cmd_options.join(', ')}).execute #{app_indent}#{cmd_indent} end #{app_indent}#{cmd_indent}end diff --git a/lib/tty/templates/add/command.rb.tt b/lib/tty/templates/add/command.rb.tt index e05af30..9686925 100644 --- a/lib/tty/templates/add/command.rb.tt +++ b/lib/tty/templates/add/command.rb.tt @@ -1,19 +1,19 @@ # frozen_string_literal: true -require_relative '<%= cmd_file_path %>' +require_relative "<%= cmd_file_path %>" <%- app_constantinized_parts.each_with_index do |const, i| -%> -<%= ' ' * i %>module <%= const %> +<%= " " * i %>module <%= const %> <%- end -%> <%= app_indent %>module Commands <%- cmd_constantinized_parts.each_with_index do |const, i| -%> <%- if cmd_constantinized_parts.size == (i + 1) -%> -<%= app_indent %><%= ' ' * i %> class <%= const %> < <%= app_constantinized_parts.join('::') %>::Command +<%= app_indent %><%= " " * i %> class <%= const %> < <%= app_constantinized_parts.join("::") %>::Command <%- else -%> -<%= app_indent %><%= ' ' * i %> class <%= const %> +<%= app_indent %><%= " " * i %> class <%= const %> <%- end -%> <%- end -%> -<%= app_indent %><%= cmd_indent %> def initialize(<%= cmd_options.join(', ') %>) +<%= app_indent %><%= cmd_indent %> def initialize(<%= cmd_options.join(", ") %>) <%- cmd_options.each do |option| -%> <%= app_indent %><%= cmd_indent %> <%= "@#{option} = #{option}" %> <%- end -%> @@ -24,8 +24,8 @@ require_relative '<%= cmd_file_path %>' <%= app_indent %><%= cmd_indent %> output.puts "OK" <%= app_indent %><%= cmd_indent %> end <%- (cmd_constantinized_parts.size).downto(1) do |i| -%> -<%= app_indent + (' ' * i) %>end +<%= app_indent + (" " * i) %>end <%- end -%> <%- (app_constantinized_parts.size).downto(0) do |i| -%> -<%= ' ' * i %>end +<%= " " * i %>end <%- end -%> diff --git a/lib/tty/templates/add/namespace.rb.tt b/lib/tty/templates/add/namespace.rb.tt index 9196eb0..1c93918 100644 --- a/lib/tty/templates/add/namespace.rb.tt +++ b/lib/tty/templates/add/namespace.rb.tt @@ -1,17 +1,17 @@ # frozen_string_literal: true -require 'thor' +require "thor" <%- app_constantinized_parts.each_with_index do |const, i| -%> -<%= ' ' * i %>module <%= const %> +<%= " " * i %>module <%= const %> <%- end -%> <%= app_indent %>module Commands <%= app_indent %> class <%= cmd_name_constantinized %> < Thor <%= app_indent %> namespace :<%= cmd_name_underscored %> <%- (cmd_constantinized_parts.size - 1).downto(1) do |i| -%> -<%= app_indent + (' ' * i) %>end +<%= app_indent + (" " * i) %>end <%- end -%> <%- (app_constantinized_parts.size).downto(0) do |i| -%> -<%= ' ' * i %>end +<%= " " * i %>end <%- end -%> diff --git a/spec/integration/add_desc_args_spec.rb b/spec/integration/add_desc_args_spec.rb index 120e73b..0ecbc33 100644 --- a/spec/integration/add_desc_args_spec.rb +++ b/spec/integration/add_desc_args_spec.rb @@ -4,7 +4,7 @@ it "adds command with description and custom arguments" do app_path = "newcli" cli_template = <<-EOS -require 'thor' +require "thor" module Newcli class CLI < Thor @@ -37,19 +37,19 @@ class CLI < Thor expect(status.exitstatus).to eq(0) expect(::File.read("lib/newcli/cli.rb")).to eq <<-EOS -require 'thor' +require "thor" module Newcli class CLI < Thor - desc 'config ARG1 ARG2', 'Set and get configuration option' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "config ARG1 ARG2", "Set and get configuration option" + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def config(arg1, arg2) if options[:help] - invoke :help, ['config'] + invoke :help, ["config"] else - require_relative 'commands/config' + require_relative "commands/config" Newcli::Commands::Config.new(arg1, arg2, options).execute end end @@ -60,7 +60,7 @@ def config(arg1, arg2) expect(::File.read("lib/newcli/commands/config.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../command' +require_relative "../command" module Newcli module Commands @@ -124,7 +124,7 @@ def execute(input: $stdin, output: $stdout) it "adds command with variadic number of arguments" do app_path = "newcli" cli_template = <<-EOS -require 'thor' +require "thor" module Newcli class CLI < Thor @@ -157,19 +157,19 @@ class CLI < Thor expect(status.exitstatus).to eq(0) expect(::File.read("lib/newcli/cli.rb")).to eq <<-EOS -require 'thor' +require "thor" module Newcli class CLI < Thor - desc 'config ARG1 NAMES...', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "config ARG1 NAMES...", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def config(arg1, *names) if options[:help] - invoke :help, ['config'] + invoke :help, ["config"] else - require_relative 'commands/config' + require_relative "commands/config" Newcli::Commands::Config.new(arg1, names, options).execute end end @@ -180,7 +180,7 @@ def config(arg1, *names) expect(::File.read("lib/newcli/commands/config.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../command' +require_relative "../command" module Newcli module Commands @@ -281,8 +281,8 @@ class CLI < Thor module Newcli class CLI < Thor - require_relative 'commands/config' - register Newcli::Commands::Config, 'config', 'config [SUBCOMMAND]', 'Set configuration option' + require_relative "commands/config" + register Newcli::Commands::Config, "config", "config [SUBCOMMAND]", "Set configuration option" end end EOS @@ -290,7 +290,7 @@ class CLI < Thor expect(::File.read("lib/newcli/commands/config.rb")).to eq <<-EOS # frozen_string_literal: true -require 'thor' +require "thor" module Newcli module Commands @@ -298,14 +298,14 @@ class Config < Thor namespace :config - desc 'set NAME [VALUE]', 'Set configuration option' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "set NAME [VALUE]", "Set configuration option" + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def set(name, value = nil) if options[:help] - invoke :help, ['set'] + invoke :help, ["set"] else - require_relative 'config/set' + require_relative "config/set" Newcli::Commands::Config::Set.new(name, value, options).execute end end @@ -317,7 +317,7 @@ def set(name, value = nil) expect(::File.read("lib/newcli/commands/config/set.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../../command' +require_relative "../../command" module Newcli module Commands diff --git a/spec/integration/add_force_spec.rb b/spec/integration/add_force_spec.rb index 6ecac83..7941546 100644 --- a/spec/integration/add_force_spec.rb +++ b/spec/integration/add_force_spec.rb @@ -4,7 +4,7 @@ it "forces adding already existing command" do app_path = "newcli" cli_template = <<-EOS -require 'thor' +require "thor" module Newcli class CLI < Thor @@ -78,7 +78,7 @@ def execute(input: $stdin, output: $stdout) expect(::File.read("lib/newcli/commands/config.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../command' +require_relative "../command" module Newcli module Commands diff --git a/spec/integration/add_namespaced_spec.rb b/spec/integration/add_namespaced_spec.rb index 68d4755..3123ba9 100644 --- a/spec/integration/add_namespaced_spec.rb +++ b/spec/integration/add_namespaced_spec.rb @@ -27,7 +27,7 @@ expect(::File.read("lib/cli/app/commands/server.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../command' +require_relative "../command" module Cli module App @@ -71,14 +71,14 @@ def version end map %w[--version -v] => :version - desc 'server', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "server", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def server(*) if options[:help] - invoke :help, ['server'] + invoke :help, ["server"] else - require_relative 'commands/server' + require_relative "commands/server" Cli::App::Commands::Server.new(options).execute end end @@ -174,8 +174,8 @@ def version end map %w[--version -v] => :version - require_relative 'commands/config' - register Cli::App::Commands::Config, 'config', 'config [SUBCOMMAND]', 'Command description...' + require_relative "commands/config" + register Cli::App::Commands::Config, "config", "config [SUBCOMMAND]", "Command description..." end end end @@ -186,7 +186,7 @@ def version expect(::File.read("lib/cli/app/commands/config.rb")).to eq <<-EOS # frozen_string_literal: true -require 'thor' +require "thor" module Cli module App @@ -195,14 +195,14 @@ class Config < Thor namespace :config - desc 'set', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "set", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def set(*) if options[:help] - invoke :help, ['set'] + invoke :help, ["set"] else - require_relative 'config/set' + require_relative "config/set" Cli::App::Commands::Config::Set.new(options).execute end end @@ -217,7 +217,7 @@ def set(*) expect(::File.read("lib/cli/app/commands/config/set.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../../command' +require_relative "../../command" module Cli module App diff --git a/spec/integration/add_spec.rb b/spec/integration/add_spec.rb index 65f8f6e..c0639de 100644 --- a/spec/integration/add_spec.rb +++ b/spec/integration/add_spec.rb @@ -45,7 +45,7 @@ expect(::File.read("lib/newcli/commands/server.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../command' +require_relative "../command" module Newcli module Commands @@ -84,14 +84,14 @@ def version end map %w[--version -v] => :version - desc 'server', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "server", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def server(*) if options[:help] - invoke :help, ['server'] + invoke :help, ["server"] else - require_relative 'commands/server' + require_relative "commands/server" Newcli::Commands::Server.new(options).execute end end @@ -238,14 +238,14 @@ class CLI < Thor module Newcli class CLI < Thor - desc 'server', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "server", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def server(*) if options[:help] - invoke :help, ['server'] + invoke :help, ["server"] else - require_relative 'commands/server' + require_relative "commands/server" Newcli::Commands::Server.new(options).execute end end @@ -297,14 +297,14 @@ class CLI < Thor module Newcli class CLI < Thor - desc 'init', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "init", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def init(*) if options[:help] - invoke :help, ['init'] + invoke :help, ["init"] else - require_relative 'commands/init' + require_relative "commands/init" Newcli::Commands::Init.new(options).execute end end @@ -331,26 +331,26 @@ def init(*) module Newcli class CLI < Thor - desc 'clone', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "clone", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def clone(*) if options[:help] - invoke :help, ['clone'] + invoke :help, ["clone"] else - require_relative 'commands/clone' + require_relative "commands/clone" Newcli::Commands::Clone.new(options).execute end end - desc 'init', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "init", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def init(*) if options[:help] - invoke :help, ['init'] + invoke :help, ["init"] else - require_relative 'commands/init' + require_relative "commands/init" Newcli::Commands::Init.new(options).execute end end @@ -391,7 +391,7 @@ class CLI < Thor expect(::File.read("lib/newcli/commands/new_server_command.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../command' +require_relative "../command" module Newcli module Commands @@ -415,14 +415,14 @@ def execute(input: $stdin, output: $stdout) module Newcli class CLI < Thor - desc 'new_server_command', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "new_server_command", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def new_server_command(*) if options[:help] - invoke :help, ['new_server_command'] + invoke :help, ["new_server_command"] else - require_relative 'commands/new_server_command' + require_relative "commands/new_server_command" Newcli::Commands::NewServerCommand.new(options).execute end end @@ -464,7 +464,7 @@ class CLI < Thor expect(::File.read("lib/newcli/commands/new_server_command.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../command' +require_relative "../command" module Newcli module Commands @@ -488,14 +488,14 @@ def execute(input: $stdin, output: $stdout) module Newcli class CLI < Thor - desc 'new_server_command', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "new_server_command", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def new_server_command(*) if options[:help] - invoke :help, ['new_server_command'] + invoke :help, ["new_server_command"] else - require_relative 'commands/new_server_command' + require_relative "commands/new_server_command" Newcli::Commands::NewServerCommand.new(options).execute end end diff --git a/spec/integration/add_subcommand_spec.rb b/spec/integration/add_subcommand_spec.rb index 6e5b054..f2d1b15 100644 --- a/spec/integration/add_subcommand_spec.rb +++ b/spec/integration/add_subcommand_spec.rb @@ -46,8 +46,8 @@ def version end map %w[--version -v] => :version - require_relative 'commands/config' - register Newcli::Commands::Config, 'config', 'config [SUBCOMMAND]', 'Command description...' + require_relative "commands/config" + register Newcli::Commands::Config, "config", "config [SUBCOMMAND]", "Command description..." end end EOS @@ -55,7 +55,7 @@ def version expect(::File.read("lib/newcli/commands/config.rb")).to eq <<-EOS # frozen_string_literal: true -require 'thor' +require "thor" module Newcli module Commands @@ -63,14 +63,14 @@ class Config < Thor namespace :config - desc 'set', 'Command description...' - method_option :help, aliases: '-h', type: :boolean, - desc: 'Display usage information' + desc "set", "Command description..." + method_option :help, aliases: "-h", type: :boolean, + desc: "Display usage information" def set(*) if options[:help] - invoke :help, ['set'] + invoke :help, ["set"] else - require_relative 'config/set' + require_relative "config/set" Newcli::Commands::Config::Set.new(options).execute end end @@ -84,7 +84,7 @@ def set(*) expect(::File.read("lib/newcli/commands/config/set.rb")).to eq <<-EOS # frozen_string_literal: true -require_relative '../../command' +require_relative "../../command" module Newcli module Commands @@ -167,6 +167,7 @@ def execute(input: $stdin, output: $stdout) create spec/unit/config/get_spec.rb create lib/newcli/commands/config/get.rb create lib/newcli/templates/config/get/.gitkeep + inject lib/newcli/cli.rb inject lib/newcli/commands/config.rb OUT expect(err).to eq("")