Class: GitHubBackup::Options

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/utils/options.rb', line 6

def options
  @options
end

Class Method Details

.is_valid?Boolean

check required options

Returns:

  • (Boolean)


78
79
80
81
82
# File 'lib/utils/options.rb', line 78

def is_valid?
    return false unless self.options[:bakdir] && File.exists?(self.options[:bakdir])
    return false unless self.options[:username]
    true
end

.parseObject



7
8
9
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
71
72
73
74
75
# File 'lib/utils/options.rb', line 7

def parse
    self.options ||= {}

    optparse = OptionParser.new do|opts|
        
        opts.banner = "Usage: github-backup -u [username] -o [dir]
e.g
github-backup -u hbt -o /tmp \n\n"


        opts.on( '-u', '--username USERNAME', '*Required: GitHub username') do |f|
            self.options[:username] = f
        end

        opts.on( '-o', '--output-dir DIR', '*Required: Backup directory') do |f|
            self.options[:bakdir] = File.expand_path(f)
        end

        opts.on( '-p', '--password PASSWORD', 'Optional: GitHub password. Required for private repos') do |f|
            self.options[:passwd] = f
        end

        opts.on( '-O', '--organization ORGANIZATION_NAME', 'Optional: Organization name of the organization to fetch repositories from') do |f|
          self.options[:organization] = f
        end

        opts.on( '-r', '--repository-name NAME', 'Optional: limit to this repository name' ) do |f|
            self.options[:reponame] = f
        end

        opts.on( '-f', '--forks', 'Optional: fetch all forks' ) do
            self.options[:forks] = true
        end

        opts.on( '-b', '--init-branches', 'Optional: init all branches' ) do
            self.options[:init_branches] = true
        end

        opts.on( '-i', '--dump-issues', 'Optional: dump all issues' ) do
            self.options[:issues] = true
        end

        opts.on( '-w', '--wiki', 'Optional: dump wiki' ) do
            self.options[:wiki] = true
        end

        opts.on( '-C', '--compress', 'Optional: run gc to compress git repo' ) do
            self.options[:repack] = true
        end

        opts.on( '-v', '--version', 'Displays current version ' ) do
            version = File.expand_path(File.dirname(__FILE__) + '../../../VERSION')
            p "Version: " + File.read(version)[0...-1] if File.exists? version
            exit
        end

        opts.on( '-h', '--help', 'Displays this screen' ) do
            p opts
            exit
        end
    end

    optparse.parse!

    if !is_valid?
        puts optparse
        exit
    end
end