Class: Tagfish::SearchCommand

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/tagfish/search_command.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tagfish/search_command.rb', line 8

def execute
  if not registry and not keyword
    abort("You need to specify a REGISTRY and/or a KEYWORD")
  end
  
  docker_uri = DockerURI.parse(registry + "/" + "dummy")
  docker_api = DockerAPI.new(docker_uri)
  
  if docker_api.api_version == 'v2'
    puts search_v2(keyword, docker_api, docker_uri)
  else
    puts search_v1(keyword, docker_api)
  end
end

#search_v1(keyword, docker_api) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/tagfish/search_command.rb', line 31

def search_v1(keyword, docker_api)
  if not keyword
    abort("You need to specify a keyword to search a Registry V1")
  end
  repos_raw = docker_api.search_v1(keyword)
  repos = repos_raw["results"].map {|result| result["name"]}
end

#search_v2(keyword, docker_api, docker_uri) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/tagfish/search_command.rb', line 23

def search_v2(keyword, docker_api, docker_uri)
  repos = docker_api.catalog_v2["repositories"]
  if keyword
    repos.select! {|repo| repo.include? keyword}
  end
  repos.map {|repo| "#{docker_uri.registry}/#{repo}"} 
end