Class: GitHubBackup::Options
- Inherits:
-
Object
- Object
- GitHubBackup::Options
- Defined in:
- lib/utils/options.rb
Class Attribute Summary collapse
-
.options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.is_valid? ⇒ Boolean
check required options.
- .parse ⇒ Object
Class Attribute Details
.options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/utils/options.rb', line 6 def @options end |
Class Method Details
.is_valid? ⇒ Boolean
check required options
78 79 80 81 82 |
# File 'lib/utils/options.rb', line 78 def is_valid? return false unless self.[:bakdir] && File.exists?(self.[:bakdir]) return false unless self.[:username] true end |
.parse ⇒ Object
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. ||= {} optparse = OptionParser.new do|opts| opts. = "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.[:username] = f end opts.on( '-o', '--output-dir DIR', '*Required: Backup directory') do |f| self.[:bakdir] = File.(f) end opts.on( '-p', '--password PASSWORD', 'Optional: GitHub password. Required for private repos') do |f| self.[:passwd] = f end opts.on( '-O', '--organization ORGANIZATION_NAME', 'Optional: Organization name of the organization to fetch repositories from') do |f| self.[:organization] = f end opts.on( '-r', '--repository-name NAME', 'Optional: limit to this repository name' ) do |f| self.[:reponame] = f end opts.on( '-f', '--forks', 'Optional: fetch all forks' ) do self.[:forks] = true end opts.on( '-b', '--init-branches', 'Optional: init all branches' ) do self.[:init_branches] = true end opts.on( '-i', '--dump-issues', 'Optional: dump all issues' ) do self.[:issues] = true end opts.on( '-w', '--wiki', 'Optional: dump wiki' ) do self.[:wiki] = true end opts.on( '-C', '--compress', 'Optional: run gc to compress git repo' ) do self.[:repack] = true end opts.on( '-v', '--version', 'Displays current version ' ) do version = File.(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 |