lib/togostanza/cli.rb in togostanza-1.3.3 vs lib/togostanza/cli.rb in togostanza-1.4.0
- old
+ new
@@ -72,10 +72,62 @@
def title
stanza_id.titleize
end
end
+ class StanzaRemover < Thor::Group
+ include Thor::Actions
+ include Thor::Shell
+
+ argument :name, type: :string
+
+ def check_input
+ input = yes?("Do you want to remove #{file_name} [y] ?")
+ unless input
+ say("This operation is canceled")
+ exit
+ end
+ end
+
+ def check_exist
+ unless File.exist?("#{file_name}")
+ say("This provider doesn't have #{file_name}")
+ exit
+ end
+ end
+
+ def remove_files
+ remove_file("#{file_name}")
+ end
+
+ def prune_gem
+ gsub_file("Gemfile", "gem '#{file_name}', path: './#{file_name}'\n", "")
+ end
+
+ def prune_gem_lock
+ run "bundle install"
+ end
+
+ private
+
+ def chop_slash
+ if name[-1] == '/'
+ name.chop
+ else
+ name
+ end
+ end
+
+ def stanza_id
+ chop_slash.underscore.sub(/_stanza$/, '')
+ end
+
+ def file_name
+ stanza_id + '_stanza'
+ end
+ end
+
class NameModifier < Thor::Group
include Thor::Actions
argument :name1, type: :string
argument :name2, type: :string
@@ -86,17 +138,15 @@
def replace_description
name1_chopped = chop_slash(name1)
name2_chopped = chop_slash(name2)
- gsub_file("#{files_name(name1_chopped)}/help.md", titles(name1_chopped), titles(name2_chopped))
- gsub_file("#{files_name(name1_chopped)}/help.md", stanzas_id(name1_chopped), stanzas_id(name2_chopped))
gsub_file("#{files_name(name1_chopped)}/#{files_name(name1_chopped)}.gemspec", files_name(name1_chopped), files_name(name2_chopped))
gsub_file("#{files_name(name1_chopped)}/lib/#{files_name(name1_chopped)}.rb", classes_name(name1_chopped), classes_name(name2_chopped))
unless File.exist?("#{files_name(name1_chopped)}/metadata.json")
- template 'metadata.json.erb', "#{file_name}/metadata.json"
+ template 'metadata.json.erb', "#{files_name(name1_chopped)}/metadata.json"
end
gsub_file("#{files_name(name1_chopped)}/metadata.json", stanzas_id(name1_chopped), stanzas_id(name2_chopped))
gsub_file("#{files_name(name1_chopped)}/stanza.rb", classes_name(name1_chopped), classes_name(name2_chopped))
gsub_file("#{files_name(name1_chopped)}/template.hbs", titles(name1_chopped), titles(name2_chopped))
@@ -128,19 +178,10 @@
else
name
end
end
- def stanza_id
- name1_chopped = chop_slash(name1)
- name1_chopped.underscore.sub(/_stanza$/, '')
- end
-
- def file_name
- stanza_id + '_stanza'
- end
-
def stanzas_id(name)
name.underscore.sub(/_stanza$/, '')
end
def files_name(name)
@@ -190,9 +231,13 @@
register StanzaGenerator, 'new', 'new NAME', 'Creates a new stanza'
end
class Stanza < Thor
register NameModifier, 'modify', 'modify OLD_NAME NEW_NAME', 'Modify a name of stanza'
+ end
+
+ class Stanza < Thor
+ register StanzaRemover, 'remove', 'remove NAME', 'Remove the stanza'
end
class Root < Thor
register NameRegister, 'name' , 'name NAME' , 'register your name'
end