Module: Travis::CLI::Gh

Extended by:
Gh
Included in:
Gh
Defined in:
lib/travis/cli/gh.rb,
lib/travis/cli/gh/cat.rb,
lib/travis/cli/gh/fetch.rb,
lib/travis/cli/gh/login.rb,
lib/travis/cli/gh/write.rb,
lib/travis/cli/gh/github.rb,
lib/travis/cli/gh/upload.rb,
lib/travis/cli/gh/whoami.rb,
lib/travis/cli/gh/version.rb,
lib/travis/cli/gh/signature.rb,
lib/travis/cli/gh/subcommands.rb

Defined Under Namespace

Modules: GitHub, Subcommands Classes: Cat, Fetch, Login, Signature, Upload, Whoami, Write

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Instance Method Details

#config_pathObject



51
52
53
# File 'lib/travis/cli/gh.rb', line 51

def config_path
  ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', ENV['HOME']) }
end

#setup(force = false) ⇒ Object



20
21
22
23
24
# File 'lib/travis/cli/gh.rb', line 20

def setup(force = false)
  setup_commands(force)
  setup_plugin(force)
  setup_completion(force)
end

#setup_commands(force) ⇒ Object



26
27
28
# File 'lib/travis/cli/gh.rb', line 26

def setup_commands(force)
  CLI.singleton_class.send(:prepend, Subcommands)
end

#setup_completion(force) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/travis/cli/gh.rb', line 40

def setup_completion(force)
  cmp_file = File.expand_path('travis.sh', config_path)
  unless File.exist?(cmp_file) and File.read(cmp_file).include?("travis-cli-gh #{VERSION}")
    require 'travis/tools/completion'
    Travis::Tools::Completion.compile
    Travis::Tools::Completion.update_completion
    content = File.read(cmp_file)
    File.write(cmp_file, "# travis-cli-gh #{VERSION}\n\n#{content}")
  end
end

#setup_plugin(force) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/travis/cli/gh.rb', line 30

def setup_plugin(force)
  target_dir = File.expand_path('travis-cli-gh', config_path)
  target     = File.expand_path('init.rb', target_dir)
  source     = File.expand_path('../../../init.rb', __dir__)
  if force or !File.exist?(target)
    FileUtils.mkdir_p(target_dir)
    FileUtils.cp(source, target)
  end
end