Class: GithubCopier::OptParser
- Inherits:
-
Object
- Object
- GithubCopier::OptParser
- Defined in:
- lib/github_copier/opt_parser.rb
Class Method Summary collapse
-
.parse(args) ⇒ Object
Return a structure describing the options.
Class Method Details
.parse(args) ⇒ Object
Return a structure describing the options.
6 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/github_copier/opt_parser.rb', line 6 def self.parse(args) # The options specified on the command line will be collected in *options*. = OpenStruct.new # Set the sensible default for the options explicitly .base_dir = "." .all_repos = false .group_by_user = false .clone_repos = false # The parser opt_parser = OptionParser.new do |opts| opts. = "Usage: github_copier [options]" opts.separator "" opts.separator "Specific options:" # Mandatory argument opts.on("-b", "--base-dir BASE_DIR", "where BASE_DIR is the directory where the repositories will be cloned to (mandatory)", "If not specified, current directory will be used") do |dir| .base_dir = dir end opts.on("-u", "--user USER", "The Github USER that will be cloned from (mandatory)") do |user| .user = user end opts.on("-o", "--org [ORG]", "The Github's organization name to be used if specified (optional)", "where ORG is the organization that the user belongs to") do |org| .org = org end opts.on("-t", "--oauth-token [OAUTH_TOKEN]", "The Github's oauth_token for authentication (optional - only required to list/clone private repositories)", "where OAUTH_TOKEN is from the user's Github setting") do |token| .oauth_token = token end opts.on("-l", "--language [LANG]", "Clone only project of type LANG (optional)", "where LANG is main language as shown on Github") do |lang| .language = lang end # Boolean switch. opts.on("-a", "--[no-]all-repos", "All repository only (optional)", "default to original/non-forked repositories only") do |a| .all_repos = a end opts.on("-g", "--[no-]group-by-user", "Group the output by {BASE_DIR}/{USER}/{LANG}", "default to {BASE_DIR}/{LANG}/{USER}") do |gbu| .group_by_user = gbu end opts.on( "-c", "--[no-]clone", "Clone the repositories to the path specified (optional)", "default to --no-clone e.g. dry-run only") do |c| .clone_repos = c end opts.separator "" opts.separator "Common options:" # No argument, shows at tail. This will print an options summary. opts.on_tail("-h", "--help", "Show this message") do puts opts puts "" puts "Example Usage:" puts "" puts "a) List the 'JavaScript' repositories for a given user (dry-run)" puts "github_copier -b ~/Desktop/projects -u awesome_user -l JavaScript" puts "" puts "b) Clone the 'JavaScript' repositories for a given user (note: --clone or -c option)" puts "github_copier -b ~/Desktop/projects -u awesome_user -l JavaScript -c" puts "" exit end end opt_parser.parse!(args) end |