Class: SyncGithubForks::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/sync_github_forks/cli.rb

Class Method Summary collapse

Class Method Details

.find_configObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sync_github_forks/cli.rb', line 12

def self.find_config
  if ENV['SYNC_GITHUB_FORKS']
    return ENV['SYNC_GITHUB_FORKS']
  end

  search_path = [
    'sync_github_forks.yaml',
    '.sync_github_forks.yaml',
    "#{ENV['HOME']}/.sync_github_forks.yaml",
    "#{ENV['HOME']}/.sync_github_forks/config.yaml"
  ]

  search_path.each do |path|
    if File.exist?(path)
      return path
    end
  end

  return nil
end

.start(args = ARGV) ⇒ Object



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
# File 'lib/sync_github_forks/cli.rb', line 39

def self.start(args = ARGV)
  options = OpenStruct.new
  options.config_file = nil
  options.github_token = nil

  OptionParser.new do |opts|
    opts.on('-c', '--config FILE', 'Use FILE as the configuration file') do |file|
      options.config_file = file
    end

    opts.on('-t', '--github_token TOKEN', 'Your GitHub Access Token',
            'Default: GITHUB_ACCESS_TOKEN environment variable'
           ) do |token|

      options.github_token = token
    end

    opts.on('-h', '--help', 'This help message') do
      puts opts
      exit
    end
  end

  # Set option defaults

  ## Config File
  unless options.config_file
    options.config_file = find_config

    unless options.config_file
      $stderr.puts("ERROR: Could not find configuration file")
      exit 1
    end
  end

  begin
    options.config = YAML.load_file(options.config_file)
  rescue StandardError
    $stderr.puts("ERROR: Config '#{options.config_file}' is not a valid YAML file")
    exit 1
  end

  ## GitHub Token
  unless options.github_token
    options.github_token = ENV['GITHUB_ACCESS_TOKEN']
  end

  unless options.github_token
    $stderr.puts('ERROR: You must set GITHUB_ACCESS_TOKEN')
    exit 1
  end

  SyncGithubForks::Ctrl.sync(options)

  return 0
end

.versionObject



33
34
35
# File 'lib/sync_github_forks/cli.rb', line 33

def self.version
  return SyncGithubForks::VERSION
end