Class: Npm2Rpm::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/npm2rpm/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



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
# File 'lib/npm2rpm/options.rb', line 13

def initialize
  # .changes format
  @date = `date -u +'%a %b %d %T UTC %Y'`
  @date.chomp!

  @email = ENV["USER"]
  @user = `getent passwd $email`.split(':')[4]
  @package = nil

  # Parse command line options
  GetoptLong.new(
    [ '-h', '--help', GetoptLong::NO_ARGUMENT ],
    [ '-H', '--man', GetoptLong::NO_ARGUMENT ],
    [ '--specdir', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--sourcedir', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--user', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--email', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--date', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--package', GetoptLong::REQUIRED_ARGUMENT ]
  ).each do |opt, arg|
    case opt
    when '--specdir'
      @specdir = arg
    when '--sourcedir'
      @sourcedir = arg
    when '--user'
      @user = arg
    when '--email'
      @email = arg
    when '--date'
      @date = arg
    when '--package'
      self.package = arg
    else
      "Run $0 -h or $0 -H for details on usage";
    end
  end
  unless ARGV.empty?
    if @package
      abort "Extra arguments: #{ARGV}"
    end
    self.package = ARGV.shift
  end

  abort 'Missing package argument' unless @package;
  abort "Extra arguments: #{ARGV}" unless ARGV.empty?;

end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



11
12
13
# File 'lib/npm2rpm/options.rb', line 11

def date
  @date
end

#emailObject (readonly)

Returns the value of attribute email.



11
12
13
# File 'lib/npm2rpm/options.rb', line 11

def email
  @email
end

#packageObject

Returns the value of attribute package.



11
12
13
# File 'lib/npm2rpm/options.rb', line 11

def package
  @package
end

#userObject (readonly)

Returns the value of attribute user.



11
12
13
# File 'lib/npm2rpm/options.rb', line 11

def user
  @user
end

#versionObject (readonly)

Returns the value of attribute version.



11
12
13
# File 'lib/npm2rpm/options.rb', line 11

def version
  @version
end