Skip to content

Commit

Permalink
Change add command templates to use double-quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Nov 8, 2020
1 parent b2c3072 commit 577d01d
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 112 deletions.
24 changes: 12 additions & 12 deletions lib/tty/commands/add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/tty/templates/add/command.rb.tt
Original file line number Diff line number Diff line change
@@ -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 -%>
Expand All @@ -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 -%>
8 changes: 4 additions & 4 deletions lib/tty/templates/add/namespace.rb.tt
Original file line number Diff line number Diff line change
@@ -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 -%>
50 changes: 25 additions & 25 deletions spec/integration/add_desc_args_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -281,31 +281,31 @@ 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

expect(::File.read("lib/newcli/commands/config.rb")).to eq <<-EOS
# frozen_string_literal: true
require 'thor'
require "thor"
module Newcli
module Commands
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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/add_force_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions spec/integration/add_namespaced_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 577d01d

Please sign in to comment.