Module: Gritano::CLI

Defined in:
lib/gritano/cli.rb

Class Method Summary collapse

Class Method Details

._execute(cmd, console) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/gritano/cli.rb', line 4

def CLI._execute(cmd, console)
  begin
    output = console.execute(cmd)
    if output[0]
      output[1].to_s
    else
      "error: #{output[1]}"
    end
  rescue
    console.execute(["help"])[1]
  end
end

.check(cmd, login, stdin = STDIN, home_dir = Etc.getpwuid.dir, repo_dir = Etc.getpwuid.dir) ⇒ Object



22
23
24
25
# File 'lib/gritano/cli.rb', line 22

def CLI.check(cmd, , stdin = STDIN, home_dir = Etc.getpwuid.dir, repo_dir = Etc.getpwuid.dir)
  Gritano::Console.remote_console(true, home_dir)
  _execute(cmd + [], Gritano::Console::Remote.new(stdin, home_dir, repo_dir))
end

.check_access(login, repo, access, home_dir = Etc.getpwuid.dir, repo_dir = Etc.getpwuid.dir) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gritano/cli.rb', line 37

def CLI.check_access(, repo, access, home_dir = Etc.getpwuid.dir, repo_dir = Etc.getpwuid.dir)
  ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(home_dir, '.gritano', 'database.yml'))))
  user = User.()
  if user
    repo = Gritano::Repository.find_by_name(repo)
    if repo
      return user.check_access(repo, access)
    end
  end
  return false
end

.check_pub_key(key, home_dir = Etc.getpwuid.dir) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/gritano/cli.rb', line 27

def CLI.check_pub_key(key, home_dir = Etc.getpwuid.dir)
  ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(home_dir, '.gritano', 'database.yml'))))
  k = Key.find_by_key(key)
  if k
    return "command=\"gritano-remote #{k.user.}\" #{k.key}"
  else
    return "invalid"
  end
end

.execute(cmd, stdin = STDIN, home_dir = Etc.getpwuid.dir, repo_dir = Etc.getpwuid.dir) ⇒ Object



17
18
19
20
# File 'lib/gritano/cli.rb', line 17

def CLI.execute(cmd, stdin = STDIN, home_dir = Etc.getpwuid.dir, repo_dir = Etc.getpwuid.dir)
  Gritano::Console.remote_console(false, home_dir)
  _execute(cmd, Gritano::Console::Gritano.new(stdin, home_dir, repo_dir))
end