Sha256: dc501a35ebe9a3afa2b2043864defda6c8e657ab641eda96d84557ae68852529

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

class GenerateCommand  < Command
  
  include Rcli::Actions

  description "Generates a template CLI script in current folder"

  def main()
        
    if @params[:args].length != 1
      puts "ERROR: You must provide a unique app name as an argument."
      exit
    end

    if File.directory? Dir.pwd + DS + @params[:args][0]
      puts "ERROR: folder already exists. Please choose another name"
      exit
    end
        
    app_name = @params[:args][0]
    
    tpl_dir = Rcli::GEM_LIB + DS + 'templates' + DS + 'new_app'
        
    # iterate through the new_app template
    Dir[ tpl_dir + DS + '**' + DS + '*.*'].each do |f|
      # TODO : Use Pathname#relative_path_from for this.
      new_file_name = f[tpl_dir.length + 1 ,f.length - tpl_dir.length]
      
      new_file_name.gsub!(/RCLIAPPNAME/,app_name)

      puts "creating " + app_name + DS + new_file_name
      create_file Dir.pwd() + DS + app_name + DS + new_file_name do
        contents = File.read(f)
        contents.gsub(/RCLIAPPNAME/,app_name)
      end
      
      if f == tpl_dir + DS + 'RCLIAPPNAME.rb'
        puts "Changing executable mode of " + new_file_name
        File.chmod(0755,Dir.pwd() + DS + app_name + DS + new_file_name)
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rcli-0.1.2 lib/commands/generate.rb
rcli-0.1.0 lib/commands/generate.rb