Module: RVMBS::Command
- Defined in:
- lib/rvmbs.rb
Class Method Summary collapse
-
.create_directory(options) ⇒ Object
Creates the directory.
-
.create_rvmrc(options) ⇒ Object
Creates the .rvmrc file.
-
.load_config ⇒ Object
Load config from user home dir.
- .run(args) ⇒ Object
-
.set_rvmrc_trusted(options, current_dir) ⇒ Object
Run rvm rvmrc trust command detached from console.
Class Method Details
.create_directory(options) ⇒ Object
Creates the directory.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rvmbs.rb', line 82 def self.create_directory() puts "Making new directory: #{[:directory]}" if [:verbose] begin Dir.mkdir [:directory] rescue if [:force] FileUtils.rm_rf [:directory] [:force] = false retry end puts "ERROR: directory already exists or cannot be created (try with --force)." end end |
.create_rvmrc(options) ⇒ Object
Creates the .rvmrc file.
97 98 99 100 101 102 103 104 |
# File 'lib/rvmbs.rb', line 97 def self.create_rvmrc() puts "Creating rvmrc file" if [:verbose] Dir.chdir([:directory]) File.open(".rvmrc", "w") do |f| f.write("rvm use --create #{[:implementation]}@#{[:directory]}\n") end Dir.chdir('..') end |
.load_config ⇒ Object
Load config from user home dir.
73 74 75 76 77 78 79 |
# File 'lib/rvmbs.rb', line 73 def self.load_config config_path = File.('~/.rvmbsrc') config = YAML.load_file( config_path ) if File.exists? config_path # config values @implementation = config['implementation'] || '1.9.2' end |
.run(args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rvmbs.rb', line 10 def self.run(args) = {} optsp = nil load_config optparse = OptionParser.new do |opts| optsp = opts opts. = "RVM Bootstrap - Command to create a project directory with a configured .rvmrc into. Usage: rvmbs -d <PROJECT_NAME> [options]" # This define the directory name. opts.on('-d', '--directory NAME', "The project's directory name.") do |name| [:directory] = name end # This define the ruby implementation. [:implementation] = @implementation opts.on('-i', '--ruby-implementation NAME', "The name of the Ruby implementation.") do |name| [:implementation] = name end # This force to delete de directory if already exists. [:force] = false opts.on('-f', '--force', "Delete directory if already exists.") do [:force] = true end # Verbose mode [:verbose] = false opts.on('-v', '--verbose', "Print extra info.") do [:verbose] = true end # This will print an options summary. opts.on_tail("-h", "--help", "Show this message.") do puts opts exit end end begin optparse.parse!(args) rescue OptionParser::MissingArgument puts 'rvmbs: missing argument, -h for help' exit end # Directory must be set. if [:directory] == nil puts optsp exit else create_directory() create_rvmrc() set_rvmrc_trusted(, Dir.pwd) end end |
.set_rvmrc_trusted(options, current_dir) ⇒ Object
Run rvm rvmrc trust command detached from console.
107 108 109 110 111 112 113 114 115 |
# File 'lib/rvmbs.rb', line 107 def self.set_rvmrc_trusted(, current_dir) puts "Setting rvmrc file to trusted" if [:verbose] pid = daemonize do current_dir = current_dir + "/" + [:directory] exit system "rvm rvmrc trust #{current_dir}/" end _, status = Process.waitpid2(pid) puts "ERROR: rvm rvmrc trust command fail!" if status != 0 end |