Class: TTY::Commands::New Private
- Includes:
- Licenses
- Defined in:
- lib/tty/commands/new.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The ‘new` command
Constant Summary collapse
- GEMSPEC_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Pathname(__dir__).join('../../../tty.gemspec').realpath.to_s
Constants included from Licenses
Licenses::CUSTOM, Licenses::LICENSES
Instance Attribute Summary collapse
- #app_name ⇒ Object readonly private
- #app_path ⇒ Object readonly private
- #options ⇒ Object readonly private
- #target_path ⇒ Object readonly private
- #templates ⇒ Object readonly private
Instance Method Summary collapse
- #author ⇒ Object private
- #constantinized_name ⇒ Object private
-
#execute(input: $stdin, output: $stdout) ⇒ Object
Execute the command.
- #file_options ⇒ Object private
- #gemspec_name ⇒ Object private
- #gemspec_path ⇒ Object private
- #git_author ⇒ Object private
- #git_exist? ⇒ Boolean private
-
#initialize(app_path, options) ⇒ New
constructor
private
A new instance of New.
- #namespaced_path ⇒ Object private
- #template_context ⇒ Object private
- #underscored_name ⇒ Object private
Methods included from Licenses
#license_identifiers, #licenses
Methods inherited from TTY::Cmd
#command, #constantinize, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Methods included from PathHelpers
#name_from_path, #relative_path_from, #root_path, #within_root_path
Constructor Details
#initialize(app_path, options) ⇒ New
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of New.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tty/commands/new.rb', line 38 def initialize(app_path, ) @app_path = relative_path_from(root_path, app_path) @app_name = name_from_path(app_path) @options = @pastel = Pastel.new(enabled: !['no-color']) @target_path = root_path.join(@app_path) @templater = Templater.new('new', @app_path) @runner = command(printer: :null) end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/tty/commands/new.rb', line 26 def app_name @app_name end |
#app_path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/tty/commands/new.rb', line 28 def app_path @app_path end |
#options ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/tty/commands/new.rb', line 31 def @options end |
#target_path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/tty/commands/new.rb', line 34 def target_path @target_path end |
#templates ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 |
# File 'lib/tty/commands/new.rb', line 36 def templates @templates end |
Instance Method Details
#author ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 62 63 64 65 |
# File 'lib/tty/commands/new.rb', line 57 def if !Array(['author']).empty? ['author'].join(', ') elsif !.empty? else 'TODO: Write your name' end end |
#constantinized_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
75 76 77 |
# File 'lib/tty/commands/new.rb', line 75 def constantinized_name constantinize(app_name) end |
#execute(input: $stdin, output: $stdout) ⇒ Object
Execute the command
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/tty/commands/new.rb', line 109 def execute(input: $stdin, output: $stdout) output.puts "OPTS: #{}" if ['debug'] coc_opt = ['coc'] ? '--coc' : '--no-coc' ext_opt = ['ext'] ? '--ext' : '--no-ext' test_opt = ['test'] command = [ "bundle gem #{target_path}", '--no-mit', '--no-exe', coc_opt, ext_opt, "-t #{test_opt}" ].join(' ') install_info = [] @runner.run(command) do |out, err| next unless out out.each_line do |line| if line =~ /^Initializing git/ install_info << line.rstrip.dup next elsif line =~ /^(Gem.*?was successfully created)/ next end if !['no-color'] output.puts color_actions(line.rstrip) else output.puts line.rstrip end end end add_app_templates add_empty_directories add_required_libs_to_gemspec @templater.generate(template_context, ) make_executable output.puts install_info.join("\n") unless install_info.empty? output.print "\n" + @pastel.green("Your teletype project has been created successfully.\n") output.print "\n" + @pastel.green("Run \"teletype help\" for more commands.\n") end |
#file_options ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 94 95 96 |
# File 'lib/tty/commands/new.rb', line 91 def opts = {} opts[:force] = true if ['force'] opts[:color] = false if ['no-color'] opts end |
#gemspec_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
98 99 100 |
# File 'lib/tty/commands/new.rb', line 98 def gemspec_name "#{app_name}.gemspec" end |
#gemspec_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
102 103 104 |
# File 'lib/tty/commands/new.rb', line 102 def gemspec_path target_path.join("#{app_name}.gemspec").to_s end |
#git_author ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/tty/commands/new.rb', line 53 def git_exist? ? `git config user.name`.chomp : '' end |
#git_exist? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 |
# File 'lib/tty/commands/new.rb', line 49 def git_exist? exec_exist?('git') end |
#namespaced_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 |
# File 'lib/tty/commands/new.rb', line 67 def namespaced_path app_name.tr('-', '/') end |
#template_context ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/tty/commands/new.rb', line 79 def template_context opts = OpenStruct.new opts[:app_name] = app_name opts[:author] = opts[:namespaced_path] = namespaced_path opts[:underscored_name] = underscored_name opts[:constantinized_name] = constantinized_name opts[:constantinized_parts] = constantinized_name.split('::') opts[:indent] = ' ' * constantinized_name.split('::').size opts end |
#underscored_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'lib/tty/commands/new.rb', line 71 def underscored_name app_name.tr('-', '_') end |