Class: Screeninator::Cli
- Inherits:
-
Object
- Object
- Screeninator::Cli
- Extended by:
- Helper
- Defined in:
- lib/screeninator/cli.rb
Constant Summary
Constants included from Helper
Class Method Summary collapse
- .copy(*args) ⇒ Object
- .customize(*args) ⇒ Object
- .delete(*args) ⇒ Object
-
.help ⇒ Object
print the usage string, this is a fall through method.
- .implode(*args) ⇒ Object
- .info(*args) ⇒ Object
-
.open(*args) ⇒ Object
Open a config file, it's created if it doesn't exist already.
- .start(*args) ⇒ Object
- .update(*args) ⇒ Object
Methods included from Helper
Class Method Details
.copy(*args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/screeninator/cli.rb', line 53 def copy(*args) @copy = args.shift @name = args.shift @config_to_copy = "#{root_dir}#{@copy}.yml" exit!("Project #{@copy} doesn't exist!") unless File.exists?(@config_to_copy) exit!("You must specify a name for the new project") unless @name file_path = "#{root_dir}#{@name}.yml" if File.exists?(file_path) confirm!("#{@name} already exists, would you like to overwrite it? (type yes or no):") do FileUtils.rm(file_path) puts "Overwriting #{@name}" end end open(@name) end |
.customize(*args) ⇒ Object
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 |
# File 'lib/screeninator/cli.rb', line 123 def customize(*args) @type = args.shift @action = args.shift if !['config','template'].include?(@type) puts "Usage: screeninator customize [config|template]" puts "config - This is the default YAML config file to use." puts "template - This is the default screen config template, complete with ERB" exit end FileUtils.mkdir_p(root_dir+"defaults") path = case @type when "config"; USER_CONFIG when "template"; USER_SCREEN_CONFIG end if @action.nil? system("$EDITOR #{path}") end if @action == "delete" confirm!("Are you sure you want to delete #{path}? (type yes or no):") do FileUtils.rm(path) puts "Deleted #{path}" end end end |
.delete(*args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/screeninator/cli.rb', line 73 def delete(*args) puts "warning: passing multiple arguments to delete will be ignored" if args.size > 1 filename = args.shift files = Dir["#{root_dir}#{filename}*"] unless files.empty? confirm!("Are you sure you want to delete #{filename}? (type yes or no):") do FileUtils.rm(files) puts "Deleted #{filename}" end end update end |
.help ⇒ Object
print the usage string, this is a fall through method.
34 35 36 |
# File 'lib/screeninator/cli.rb', line 34 def help puts HELP_TEXT end |
.implode(*args) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/screeninator/cli.rb', line 88 def implode(*args) exit!("delete_all doesn't accapt any arguments!") unless args.empty? confirm!("Are you sure you want to delete all screeninator configs? (type yes or no):") do FileUtils.remove_dir(root_dir) puts "Deleted #{root_dir}" end end |
.info(*args) ⇒ Object
101 102 103 104 |
# File 'lib/screeninator/cli.rb', line 101 def info(*args) puts "screeninator configs:" list(true) end |
.open(*args) ⇒ Object
Open a config file, it's created if it doesn't exist already.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/screeninator/cli.rb', line 39 def open(*args) @name = args.shift FileUtils.mkdir_p(root_dir+"scripts") config_path = "#{root_dir}#{@name}.yml" unless File.exists?(config_path) template = File.exists?(user_config) ? user_config : "#{File.dirname(__FILE__)}/assets/sample.yml" erb = ERB.new(File.read(template)).result(binding) tmp = File.open(config_path, 'w') {|f| f.write(erb) } end system("$EDITOR #{config_path}") update(@name) end |
.start(*args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/screeninator/cli.rb', line 18 def start(*args) begin if args.empty? self.help else self.send(args.shift, *args) end rescue NoMethodError => e puts e self.help end end |
.update(*args) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/screeninator/cli.rb', line 106 def update(*args) aliases = [] Dir["#{root_dir}*.yml"].each do |path| begin path = File.basename(path, '.yml') config_name = path.split("/").last begin; FileUtils.rm("#{path}.screen"); rescue; end aliases << Screeninator::ConfigWriter.new(path).write! rescue ArgumentError => e puts e end end Screeninator::ConfigWriter.write_aliases(aliases) end |