Class: GithubCloner::OptParser
- Inherits:
-
Object
- Object
- GithubCloner::OptParser
- Defined in:
- lib/github_cloner/opt_parser.rb
Overview
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.
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/github_cloner/opt_parser.rb', line 7 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 = "." .repo_host = "github.com" .all_repos = false # options.group_by_user = false .clone_repos = false .languages = [] opt_parser = OptionParser.new do |opts| opts. = "Usage: github-cloner [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", "--languages 'LANG1,LANG2,..,LANGn'", Array, "Clone all repos that in the list of languages") do |langs| .languages = langs end opts.on("-r", "--repo-host REPO_HOST", "where REPO_HOST is the repository host to be cloned from", "If not specified, github.com will be used") do |host| .repo_host = host end # Boolean switch. opts.on("-a", "--[no-]all-repos", "All repository only (optional)", "default to original/non-forked repositories only") do |all_repos| .all_repos = all_repos end # opts.on("-g", "--[no-]group-by-user", # "Group the output by {BASE_DIR}/{USER}/{LANG}", # "default to {BASE_DIR}/{LANG}/{USER}") do |gbu| # options.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 "1) List all repositories by a given user (dry-run)" puts "$github-cloner -u awesome_user" puts "" puts "2) List all 'Emacs Lisp' repositories for a given user (dry-run)" puts "$github-cloner -b ~/Desktop/projects -u awesome_user -l 'Emacs Lisp'" puts "" puts "3) List all 'JavaScript' and 'Emacs Lisp' repositories for a given user (dry-run)" puts "$github-cloner -b ~/Desktop/projects -u awesome_user -l 'JavaScript,Emacs Lisp'" puts "" puts "4) Clone all 'JavaScript' and 'Emacs Lisp' repositories for a given user (note: --clone or -c option)" puts "$github-cloner -b ~/Desktop/projects -u awesome_user -l 'JavaScript,Emacs Lisp' -c" puts "" puts "5) Clone all 'JavaScript' and 'Emacs Lisp' repositories for a given organization where a given user belongs to (include private repos)" puts "$github-cloner -b ~/Desktop/projects -u awesome_user -o awesome_company -t GITHUB_TOKEN -l 'JavaScript,Emacs Lisp' -c" puts "" puts "6) Clone all 'JavaScript' and 'Emacs Lisp' repositories for a given organization where a given user belongs to (include private repos)" puts " Using the host configured in ~/.ssh/config file instead of the default github.com" puts "$github-cloner -b ~/Desktop/projects -u awesome_user -o awesome_company -t GITHUB_TOKEN -l 'JavaScript,Emacs Lisp' -r github-work -c" puts "" exit end end opt_parser.parse!(args) end |