Class: Uas2Git::Main
- Inherits:
-
Object
- Object
- Uas2Git::Main
- Defined in:
- lib/uas2git/main.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ Main
constructor
A new instance of Main.
- #parse(args) ⇒ Object
- #run! ⇒ Object
- #show_help_message(msg) ⇒ Object
Constructor Details
#initialize(args) ⇒ Main
Returns a new instance of Main.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/uas2git/main.rb', line 8 def initialize(args) @options = parse(args) ('Missing PROJECT_NAME parameter') if args.empty? ('Too many arguments') if args.size > 1 @project_name = args.first begin ('The repository must be empty') unless Rugged::Repository.new('.').empty? rescue end end |
Instance Method Details
#parse(args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/uas2git/main.rb', line 52 def parse(args) # Set up reasonable defaults for options. = {} [:host] = 'localhost' [:username] = 'admin' @opts = OptionParser.new do |opts| opts. = 'Usage: uas2git PROJECT_NAME [options]' opts.separator '' opts.separator 'Specific options:' opts.on('-h HOSTNAME', 'Unity Asset Server host (default: "localhost")') do |host| [:host] = host end opts.on('-U NAME', 'Unity Asset Server user name (default: "admin")') do |username| [:username] = username end opts.separator '' opts.on_tail('--help', 'Show this message') do puts opts exit end end @opts.parse! args end |
#run! ⇒ Object
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 |
# File 'lib/uas2git/main.rb', line 23 def run! password = ask('Enter password for ' + @options[:username] + '@' + @options[:host] + ': ') { |q| q.echo = false } ActiveRecord::Base.establish_connection( :adapter => 'postgresql', :host => @options[:host], :port => '10733', :username => @options[:username], :password => password, :database => @project_name ) # Initialize a git repository repo = Progress.start('Initializing a git repository', 1) do Progress.step do Rugged::Repository.init_at('.') end end Migrator.new(repo).migrate! # Checking out the working copy Progress.start('Checking out the work tree', 1) do Progress.step do repo.reset('HEAD', :hard) end end end |
#show_help_message(msg) ⇒ Object
84 85 86 87 88 |
# File 'lib/uas2git/main.rb', line 84 def (msg) puts "Error starting script: #{msg}\n\n" puts @opts.help exit end |