teuton-get 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6798e051552f8894c95ead5df65fe64b68d34bf34e79aeed4f9d841b199d2c83
4
- data.tar.gz: f875b6b84834d25b81d312e292e566978474242709b868e0697eede5e903f163
3
+ metadata.gz: 562a19d3826cb7c518ab1233512970a4891cc6c27c187ed8950b9719efb626f1
4
+ data.tar.gz: 7ecf0a49739e45e824bd5d6ab95f0f0e7372a1ef6712f6262549e72f4df2ac00
5
5
  SHA512:
6
- metadata.gz: e75bd99ed2db3b3e7ae6ac29e8cdad90538fdb248839cd01a91eb3c928f3cc60e256bd4679e585d5f41e8bf74a5033c69e60bb34b1933792a706756122bee73d
7
- data.tar.gz: 8876f1b70c0e3e611212d3d09d271d156700220c62cf9a5057444313edc5129382c6a652933d806c514010106ccd193e29403229b2e8a2bb48ac1c6404b8f253
6
+ metadata.gz: 0bf1ab586485046eaac4198bfccd93fd96c4571fcf377f3de1a5a13090c5f5994d3f9e51ade60b11e9ce4474f4d404cd927cc6c9ca646f02b4203453634913e6
7
+ data.tar.gz: d8a419372d1559f5ac44f8279d3699120fa5c16c8192fe6aae6301256c96d26d607e8fc81be5d423ba53d2e3da00f8fe06249e2b210f6bb25a3620ed5ecbe2cc
data/README.md CHANGED
@@ -7,9 +7,7 @@
7
7
  * Find and download _Teuton Tests_ from remote or local repositories.
8
8
  * Create _Teuton Test_ repository.
9
9
 
10
- ![logo](./docs/images/logo.png)
11
-
12
- # Installation
10
+ ## Installation
13
11
 
14
12
  First install Ruby, then:
15
13
 
@@ -17,13 +15,12 @@ First install Ruby, then:
17
15
  gem install teuton-get
18
16
  ```
19
17
 
20
- # Usage
18
+ ## Usage
21
19
 
22
20
  * At first, **create config file**.
23
21
 
24
- ```
25
- > teutonget init
26
-
22
+ ```bash
23
+ $ teutonget init
27
24
  ==> Creating configuration files
28
25
  ✔ Create dir : /home/quigon/.config/teuton
29
26
  ✔ Create file : /home/quigon/.config/teuton/repos.ini
@@ -31,26 +28,24 @@ gem install teuton-get
31
28
 
32
29
  * **Refresh** repo catalog, from time to time:
33
30
 
34
- ```
35
- > teutonget refresh
36
-
31
+ ```bash
32
+ $ teutonget refresh
37
33
  ==> Refreshing active repos
38
34
  ✔ Repo teuton.en (10 tests)
39
35
  ✔ Repo teuton.es (4 tests)
40
36
  ```
41
37
 
42
- * **Search** test related with "usermin":
38
+ * **Search** test related with *usermin*:
43
39
 
44
- ```
45
- > teutonget search usermin
40
+ ```bash
41
+ $ teutonget search usermin
46
42
  (x3) teuton.es:sistemas.3/scripting/usermin
47
43
  ```
48
44
 
49
- * Take a look at **test info**:
50
-
51
- ```
52
- > teutonget info teuton.es:sistemas.3/scripting/usermin
45
+ * **Show** test info:
53
46
 
47
+ ```bash
48
+ $ teutonget show teuton.es:sistemas.3/scripting/usermin
54
49
  name : usermin
55
50
  author : fvarrui, dvarrui
56
51
  date : 2022-11-05
@@ -59,26 +54,58 @@ tags : script, usuario, crear, consultar, listar, eliminar
59
54
  files : INSTALL.md, README.md, bin/docker.run, bin/up_environ.sh, config.yaml, lib/docker/consultar.rb, lib/docker/eliminar.rb, lib/docker/help.rb, lib/docker/listar.rb, lib/docker/nuevo.rb, lib/vm/consultar.rb, lib/vm/eliminar.rb, lib/vm/help.rb, lib/vm/listar.rb, lib/vm/nuevo.rb, start.rb, tt-info.yaml, vagrant/install-software.sh, vagrant/profesor.rb, vm.rb, vm.yaml
60
55
  ```
61
56
 
62
- * **Download test** "teuton.es:sistemas.3/scripting/usermin":
57
+ * **Download test** `teuton.es:sistemas.3/scripting/usermin`:
63
58
 
59
+ ```bash
60
+ $ teutonget pull teuton.es:sistemas.3/scripting/usermin
61
+ ==> Progress [██████████████] 100%
62
+ ==> Download finished
64
63
  ```
65
- > teutonget download teuton.es:sistemas.3/scripting/usermin
66
64
 
67
- ==> Progress [█████████████████████] 100%
68
- ==> Download finished
65
+ **Example:** Locate *TEST_ID* for `debian` related tests.
66
+
67
+ ```bash
68
+ $ teutonget se debian
69
+ (x04) teuton.en:systems.1/03-debian-conf
70
+ (x04) teuton.en:systems.2/02-debian-basic-configuration
71
+ (x04) teuton.en:systems.2/03-debian-mkdir-command
72
+ (x04) teuton.en:systems.2/04-debian-users-grants
73
+ (x04) teuton.en:systems.2/11-debian-custom-installation
69
74
  ```
70
75
 
71
- **Example:** Locate TEST_ID for "debian" related tests.
76
+ ## Build and install the gem from sources
77
+
78
+ You can build `teuton-get` Ruby gem from sources following the next steps:
72
79
 
73
- ![](docs/images/teutonget-search-debian.png)
80
+ 1. Clone the repo and change to its directory:
74
81
 
75
- # Documentation
82
+ ```bash
83
+ git clone https://github.com/teuton-software/teuton-get
84
+ cd teuton-get
85
+ ```
86
+
87
+ 2. Build the gem:
88
+
89
+ ```bash
90
+ rake build
91
+ ```
92
+
93
+ 3. Install newly built gem:
94
+ - On GNU/Linux or Mac OS:
95
+
96
+ ```bash
97
+ sudo gem install pkg/teuton-get-*.gem
98
+ ```
99
+
100
+ - On Windows as `Administrator`:
101
+
102
+ ```bash
103
+ gem install pkg\teuton-get-*.gem
104
+ ```
105
+
106
+ ## Documentation
76
107
 
77
108
  * [Settings](docs/settings.md)
78
109
  * [Get](docs/get.md)
79
110
  * [Repository](docs/repo.md)
80
111
  * [Commands](docs/commands.md)
81
-
82
- # Contact
83
-
84
- * **Email**: `teuton.software@protonmail.com`
data/docs/commands.md CHANGED
@@ -4,13 +4,14 @@
4
4
  Run `teutonget` to show available commands:
5
5
  ```
6
6
  Commands:
7
- teutonget create-info [TEST-PATH] # Create info data for Teuton test
8
- teutonget create-repo [SOURCE-DIR] # Create repo into SOURCE directory
9
- teutonget download REPONAME@TESTNAME # Download Teuton test
10
- teutonget help [COMMAND] # Describe available commands or one specific command
11
- teutonget init # Create ini config file
12
- teutonget refresh # Synchronize list of tests available.
13
- teutonget repos # Show repo list
14
- teutonget search [REPONAME@]FILTER # Search Teuton test with FILTER
15
- teutonget version # Show the program version
7
+ teutonget create-info DIRPATH # Create info data for Teuton test
8
+ teutonget create-repo # Create repo into current directory
9
+ teutonget help [COMMAND] # Describe available commands or one specific command
10
+ teutonget init # Create ini config file
11
+ teutonget pull TESTID # Download Teuton test
12
+ teutonget refresh # Synchronize list of available tests.
13
+ teutonget repos # Show repo list
14
+ teutonget search [REPONAME:]FILTER # Search Teuton test with FILTER
15
+ teutonget show TESTID|FILTER # Show info data for Teuton test
16
+ teutonget version # Show the program version
16
17
  ```
data/docs/get.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Find and download local or remote test files.
6
6
 
7
7
  1. [Search](#1-search)
8
- 2. [Info](#2-info)
8
+ 2. [Show](#2-show)
9
9
  3. [Download](#3-download)
10
10
 
11
11
  ## 1. Search
@@ -28,7 +28,7 @@ teutonget search FILTER
28
28
  Example:
29
29
 
30
30
  ```
31
- ❯ teutonget se window
31
+ ❯ teutonget search window
32
32
  (x3) teuton.en:systems.1/01-windows-conf
33
33
  (x1) teuton.en:systems.1/04-winserver-conf
34
34
  (x1) teuton.en:systems.2/01-install-w10-vbox
@@ -39,18 +39,19 @@ As a result we have a list of tests ordered from highest to lowest value accordi
39
39
 
40
40
  Ejample:
41
41
  ```
42
- ❯ teutonget se script,fvarrui
42
+ ❯ teutonget search script,fvarrui
43
43
  (x6) teuton.es:sistemas.3/scripting/usermin
44
44
  (x1) teuton.en:systems.2/01-install-w10-vbox
45
45
  ```
46
46
 
47
47
  In this example, the filter is form by multiple words separated by commas. As result, will be shown tests that contain word 1 or word 2, or both. And appear in order from highest to lowest according to the number of times these words appear in the test metadata.
48
48
 
49
- ## 2. Info
49
+ ## 2. Show
50
50
 
51
51
  Show info about test. Example:
52
+
52
53
  ```
53
- ❯ teutonget info teuton.en:systems.1/03-debian-conf
54
+ ❯ teutonget show teuton.en:systems.1/03-debian-conf
54
55
 
55
56
  name : Debian configuration
56
57
  author : dvarrui
@@ -65,7 +66,7 @@ files : README.md, config.yaml, debian.rb, network.rb, start.rb
65
66
  Download teuton test files identified by TESTID. Example:
66
67
 
67
68
  ```
68
- ❯ teutonget download teuton.en:systems.1/03-debian-conf
69
+ ❯ teutonget pull teuton.en:systems.1/03-debian-conf
69
70
 
70
71
  ==> Downloading...
71
72
  ==> File: README.md
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "thor"
4
- require_relative "application"
5
4
  require_relative "version"
6
5
  require_relative "../teuton-get"
7
6
 
@@ -12,83 +11,110 @@ class CLI < Thor
12
11
  desc "version", "Show the program version"
13
12
 
14
13
  def version
15
- puts "#{Version::EXECUTABLE} version #{Version::VERSION}"
14
+ puts "#{TeutonGet::EXECUTABLE} version #{TeutonGet::VERSION}"
16
15
  end
17
16
 
18
17
  map ["ci", "-ci", "--create-info", "create-info"] => "create_info"
19
- desc "create-info [DIRPATH]", "Create info data for Teuton test"
18
+ option :color, type: :boolean
19
+ desc "create-info DIRPATH", "Create info data for Teuton test"
20
20
  long_desc <<-LONGDESC
21
21
  Create info data for Teuton test. Example: "teutonget create-info systems.1/02-opensuse-conf"
22
22
  LONGDESC
23
23
 
24
- def create_info(testpath)
24
+ def create_info(testpath = ".")
25
+ TeutonGet::Format.disable if options["color"] == false
25
26
  TeutonGet.create_info(testpath)
26
27
  end
27
28
 
28
29
  map ["cr", "-cr", "--create-repo", "create-repo"] => "create_repo"
30
+ option :color, type: :boolean
29
31
  desc "create-repo", "Create repo into current directory"
30
32
  long_desc <<-LONGDESC
31
33
  Create index from SOURCE directory. Example: "teutonget create-repo"
32
34
  LONGDESC
33
35
  def create_repo
36
+ TeutonGet::Format.disable if options["color"] == false
34
37
  TeutonGet.create_repo(".")
35
38
  end
36
39
 
40
+ map ["d", "-d", "--download", "download", "--pull"] => "pull"
41
+ option :color, type: :boolean
42
+ desc "pull TESTID [DIRECTORY]", "Download Teuton test"
43
+ long_desc <<-LONGDESC
44
+ Example: "teutonget pull teuton.en:systems.1/02-opensuse-conf". Download test.
45
+ LONGDESC
46
+ def pull(testid, dirpath = ".")
47
+ TeutonGet::Format.disable if options["color"] == false
48
+ TeutonGet.download(testid, dirpath)
49
+ end
50
+
37
51
  map ["--init"] => "init"
52
+ option :color, type: :boolean
38
53
  desc "init", "Create ini config file"
39
54
  long_desc <<-LONGDESC
40
- Create ini config file. Example: "teutonget init"
55
+ Create inital configuration files. Example: "teutonget init"
41
56
  LONGDESC
42
57
  def init
58
+ TeutonGet::Format.disable if options["color"] == false
43
59
  TeutonGet.init
44
60
  end
45
61
 
46
- map ["i", "-i", "--info"] => "info"
47
- desc "info TESTID", "Show info data for Teuton test"
62
+ map ["i", "-i", "--info", "info", "--show"] => "show"
63
+ option :color, type: :boolean
64
+ option :format, type: :string
65
+ desc "show TESTID|FILTER", "Show info data for Teuton test"
48
66
  long_desc <<-LONGDESC
49
- Show info data for Teuton test. Example: "teutonget info teuton.en:systems.1/02-opensuse-conf"
50
- LONGDESC
67
+ Example: "teutonget show teuton.en:systems.1/02-opensuse-conf". Show test info.
51
68
 
52
- def info(test_id)
53
- TeutonGet.show_info(test_id)
69
+ Example: "teutonget show foo --format=json". Show test info using JSON format.
70
+ LONGDESC
71
+ def show(test_id)
72
+ TeutonGet::Format.disable if options["color"] == false
73
+ TeutonGet.show_info(test_id, options)
54
74
  end
55
75
 
56
76
  map ["--repos"] => "repos"
77
+ option :color, type: :boolean
78
+ option :format, type: :string
57
79
  desc "repos", "Show repo list"
58
80
  long_desc <<-LONGDESC
59
- Show repo list. Example: "teutonget repos"
81
+ Example: "teutonget repos". Show repo list.
82
+
83
+ Example: "teutonget repos --format=json". Show JSON repos list.
60
84
  LONGDESC
61
85
 
62
86
  def repos
63
- TeutonGet.show_repo_list
87
+ TeutonGet::Format.disable if options["color"] == false
88
+ TeutonGet.show_repo_list(options)
64
89
  end
65
90
 
66
- map ["r", "-r", "--refresh"] => "refresh"
91
+ map ["r", "-r", "--refresh", "--update", "update"] => "refresh"
92
+ option :color, type: :boolean
67
93
  desc "refresh", "Synchronize list of available tests."
68
94
  long_desc <<-LONGDESC
69
95
  Synchronize list of tests available. Example: "teutonget refresh"
70
96
  LONGDESC
71
97
  def refresh
98
+ TeutonGet::Format.disable if options["color"] == false
72
99
  TeutonGet.refresh
73
100
  end
74
101
 
75
102
  map ["s", "-s", "--search"] => "search"
103
+ option :color, type: :boolean
104
+ option :format, type: :string
76
105
  desc "search [REPONAME:]FILTER", "Search Teuton test with FILTER"
77
106
  long_desc <<-LONGDESC
78
- Search Teuton test using FILTER. Example: "teutonget search opensuse"
107
+ Example: "teutonget search opensuse". Search tests filtering by 'opensuse'.
108
+
109
+ Example: "teutonget search debian --format=json". Search tests filtering by 'debian' and show JSON format output.
79
110
  LONGDESC
80
111
  def search(filter)
81
- TeutonGet.search(filter)
112
+ TeutonGet::Format.disable if options["color"] == false
113
+ TeutonGet.search(filter, options)
82
114
  end
83
115
 
84
- map ["d", "-d", "--download", "clone", "--clone"] => "download"
85
- # option :dirname # FIXME
86
- desc "download TESTID", "Download Teuton test"
87
- long_desc <<-LONGDESC
88
- Download Teuton test. Example: "teutonget download teuton.en:systems.1/02-opensuse-conf"
89
- LONGDESC
90
- def download(testname)
91
- puts options unless options.empty?
92
- TeutonGet.download(testname, options)
116
+ def respond_to_missing?(method_name, include_private = false)
117
+ # Respond to missing methods name
118
+ super
93
119
  end
94
120
  end
@@ -6,12 +6,13 @@ require_relative "reader/inifile_reader"
6
6
  require_relative "reader/url_reader"
7
7
  require_relative "repo/repo_config"
8
8
  require_relative "repo/repo_data"
9
+ require_relative "settings"
9
10
 
10
11
  class Downloader
11
12
  def initialize
12
13
  @dev = TerminalWriter.new
13
- @repo_config = RepoConfig.new_by_default.data
14
- cache_dirpath = Application.instance.get(:cache_dirpath)
14
+ @repo_config = RepoConfig.default.data
15
+ cache_dirpath = Settings.get(:cache_dirpath)
15
16
  @repo_data = RepoData.new(
16
17
  config_reader: IniFileReader.new,
17
18
  progress_writer: TerminalWriter.new,
@@ -19,10 +20,10 @@ class Downloader
19
20
  )
20
21
  end
21
22
 
22
- def run(id)
23
- reponame, testpath = id.split(Application::SEPARATOR)
23
+ def run(id, dirpath = ".")
24
+ reponame, testpath = id.split(Settings::SEPARATOR)
24
25
 
25
- repo_url, status = get_url_for reponame
26
+ repourl, status = get_url_for reponame
26
27
  unless status == :ok
27
28
  @dev.writeln " #{status}"
28
29
  return false
@@ -34,7 +35,7 @@ class Downloader
34
35
  return false
35
36
  end
36
37
 
37
- download(reponame, repo_url, testpath, files)
38
+ download(reponame, repourl, dirpath, testpath, files)
38
39
  end
39
40
 
40
41
  private
@@ -48,19 +49,27 @@ class Downloader
48
49
  end
49
50
 
50
51
  def get_files_for_test(id)
51
- testdata = @repo_data.get(id)
52
- return [], "ERROR: not found!" if testdata.nil?
53
- files = testdata["files"]
52
+ testinfo = @repo_data.get_info(id)
53
+ return [], "ERROR: not found!" if testinfo.nil?
54
+ files = testinfo["files"]
54
55
  return [], "WARN: files no defined!" if files.nil?
55
56
  return [], "WARN: 0 files defined!" if files.size.zero?
56
57
  [files, :ok]
57
58
  end
58
59
 
59
- def download(reponame, url, path, files)
60
- bar = TTY::ProgressBar.new("==> Progress [:bar] :percent", total: files.size, bar_format: :block)
60
+ def download(reponame, url, dirpath, path, files)
61
+ bar = TTY::ProgressBar.new(
62
+ "==> Progress [:bar] :percent",
63
+ total: files.size,
64
+ bar_format: :block
65
+ )
66
+ localpath = if dirpath == "."
67
+ File.join(path.tr("/", "_"))
68
+ else
69
+ dirpath
70
+ end
71
+ FileUtils.mkdir_p(localpath) unless File.exist? localpath
61
72
 
62
- localpath = path.tr("/", "_")
63
- FileUtils.mkdir(localpath) unless File.exist? localpath
64
73
  files.each do |filename|
65
74
  bar.advance
66
75
 
@@ -1,13 +1,13 @@
1
1
  # version 1
2
2
 
3
- [teuton.en]
3
+ [dvarrui.en]
4
4
  type = teutontest
5
- description = Main Teuton repo
5
+ description = Tests repository (dvarrui)
6
6
  URL = https://raw.githubusercontent.com/teuton-software/teuton-tests/master/en
7
7
  enable = true
8
8
 
9
- [teuton.es]
9
+ [dvarrui.es]
10
10
  type = teutontest
11
- description = Repositorio principal de Teuton Test
11
+ description = Repositorio de Tests (dvarrui)
12
12
  URL = https://raw.githubusercontent.com/teuton-software/teuton-tests/master/es
13
13
  enable = true
@@ -1,4 +1,4 @@
1
- require_relative "../application"
1
+ require_relative "../settings"
2
2
  require_relative "../writer/terminal_writer"
3
3
  require_relative "../reader/yaml_reader"
4
4
  require "erb"
@@ -11,12 +11,12 @@ class LocalInfo
11
11
  @data = {}
12
12
  end
13
13
 
14
- def default_create(testpath)
14
+ def default_created(testpath)
15
15
  set_default_data(testpath)
16
16
  create(testpath)
17
17
  end
18
18
 
19
- def user_create(testpath)
19
+ def user_created(testpath)
20
20
  ask_data(testpath)
21
21
  create(testpath)
22
22
  end
@@ -36,7 +36,7 @@ class LocalInfo
36
36
 
37
37
  def set_default_data(testpath)
38
38
  @data[:name] = File.basename(testpath)
39
- @data[:author] = ENV["USER"]
39
+ @data[:author] = Settings.get("USER")
40
40
  @data[:date] = Time.now.strftime("%Y-%m-%d")
41
41
  @data[:desc] = "Write your description"
42
42
  @data[:tags] = ["Write your", "comma separated", "tags"]
@@ -60,7 +60,7 @@ class LocalInfo
60
60
  return false
61
61
  end
62
62
 
63
- infofilename = Application::INFOFILENAME
63
+ infofilename = Settings::INFOFILENAME
64
64
  sourcepath = File.join(File.dirname(__FILE__), "..", "files", infofilename)
65
65
  template = File.read(sourcepath)
66
66
  content = ERB.new(template, trim_mode: "%>")
@@ -1,4 +1,4 @@
1
- require_relative "../application"
1
+ require_relative "../settings"
2
2
  require_relative "../writer/file_writer"
3
3
  require_relative "../writer/terminal_writer"
4
4
 
@@ -9,7 +9,7 @@ class LocalRepo
9
9
  @dev = args[:progress_writer]
10
10
  end
11
11
 
12
- def self.new_by_default
12
+ def self.default
13
13
  LocalRepo.new(
14
14
  repoindex_writer: FileWriter.new,
15
15
  progress_writer: TerminalWriter.new
@@ -17,19 +17,19 @@ class LocalRepo
17
17
  end
18
18
 
19
19
  def create(dirpath)
20
- infofilename = Application::INFOFILENAME
20
+ infofilename = Settings::INFOFILENAME
21
21
  infofiles = Dir.glob(File.join(dirpath, "**", infofilename))
22
22
  return if infofiles.size.zero?
23
23
 
24
24
  @dev.writeln "\n==> Creating repository", color: :light_yellow
25
25
  data = read_files(infofiles)
26
26
 
27
- filepath = File.join(dirpath, Application::INDEXFILENAME)
27
+ filepath = File.join(dirpath, Settings::INDEXFILENAME)
28
28
  @repoindex_writer.open(filepath)
29
29
  @repoindex_writer.write data.to_yaml
30
30
  @repoindex_writer.close
31
31
 
32
- @dev.writeln " Created file #{filepath} with #{data.keys.size} tests.", color: :white
32
+ @dev.writeln " Created #{filepath} (#{data.keys.size} tests)", color: :white
33
33
  true
34
34
  end
35
35
 
@@ -1,7 +1,8 @@
1
1
  require "fileutils"
2
- require_relative "../application"
2
+ require "json/pure"
3
+ require_relative "../settings"
3
4
  require_relative "../reader/inifile_reader"
4
- require_relative "../utils/format"
5
+ require_relative "../writer/format"
5
6
  require_relative "../writer/terminal_writer"
6
7
 
7
8
  # Create Teuton Repo config file
@@ -14,16 +15,16 @@ class RepoConfig
14
15
  @dev = args[:progress_writer]
15
16
 
16
17
  @config_dirpath = args[:config_dirpath] || ""
17
- @config_filepath = File.join(@config_dirpath, Application::CONFIGFILE)
18
+ @config_filepath = File.join(@config_dirpath, Settings::CONFIGFILE)
18
19
  end
19
20
 
20
- def self.new_by_default
21
- config_filepath = Application.instance.get(:config_filepath)
21
+ def self.default
22
+ config_filepath = Settings.get(:config_filepath)
22
23
 
23
24
  RepoConfig.new(
24
25
  config_reader: IniFileReader.new(config_filepath),
25
26
  progress_writer: TerminalWriter.new,
26
- config_dirpath: Application.instance.get(:config_dirpath)
27
+ config_dirpath: Settings.get(:config_dirpath)
27
28
  )
28
29
  end
29
30
 
@@ -33,13 +34,24 @@ class RepoConfig
33
34
  create_ini_file
34
35
  end
35
36
 
36
- def show_list
37
+ def show_list(options)
38
+ if options["format"] == "json"
39
+ show_json_list
40
+ else
41
+ show_default_list
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def show_default_list
37
48
  rows = []
38
49
  rows << ["E", "NAME", "DESCRIPTION"]
39
50
  rows << :separator
40
51
 
41
52
  index = 0
42
53
  @data.each_pair do |key, value|
54
+ next unless value["type"] == "teutontest"
43
55
  enable = "\u{2714}"
44
56
  enable = " " unless value["enable"]
45
57
  description = value["description"] || "?"
@@ -52,7 +64,16 @@ class RepoConfig
52
64
  @dev.writeln "#{@reader.source}\n", color: :white
53
65
  end
54
66
 
55
- private
67
+ def show_json_list
68
+ alist = []
69
+ @data.each_pair do |key, values|
70
+ next unless values["type"] == "teutontest"
71
+
72
+ values["reponame"] = key
73
+ alist << values
74
+ end
75
+ puts JSON.dump(alist)
76
+ end
56
77
 
57
78
  def create_dir
58
79
  dirpath = @config_dirpath
@@ -73,7 +94,7 @@ class RepoConfig
73
94
  end
74
95
 
75
96
  def create_ini_file
76
- src = File.join(File.dirname(__FILE__), "..", "files", Application::CONFIGFILE)
97
+ src = File.join(File.dirname(__FILE__), "..", "files", Settings::CONFIGFILE)
77
98
  copyfile(src, @config_filepath)
78
99
  end
79
100
 
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "yaml"
2
- require_relative "../application"
4
+ require_relative "../settings"
3
5
  require_relative "../reader/url_reader"
4
6
  require_relative "../reader/inifile_reader"
5
7
  require_relative "../reader/yaml_reader"
@@ -14,12 +16,12 @@ class RepoData
14
16
  @cache_dirpath = args[:cache_dirpath]
15
17
  end
16
18
 
17
- def self.new_by_default
18
- config_filepath = Application.instance.get(:config_filepath)
19
+ def self.default
20
+ config_filepath = Settings.get(:config_filepath)
19
21
  RepoData.new(
20
22
  config_reader: IniFileReader.new(config_filepath),
21
23
  progress_writer: TerminalWriter.new,
22
- cache_dirpath: Application.instance.get(:cache_dirpath)
24
+ cache_dirpath: Settings.get(:cache_dirpath)
23
25
  )
24
26
  end
25
27
 
@@ -35,11 +37,11 @@ class RepoData
35
37
  save_database
36
38
  end
37
39
 
38
- def get(test_id)
39
- reponame, id = test_id.split(Application::SEPARATOR)
40
+ def get_info(test_id)
41
+ reponame, id = test_id.split(Settings::SEPARATOR)
40
42
  database = YamlReader.new.read(database_filename)
41
43
  return {} if database[reponame].nil?
42
- database[reponame][id]
44
+ database[reponame][id] || {}
43
45
  end
44
46
 
45
47
  def show_testinfo(item)
@@ -113,7 +115,7 @@ class RepoData
113
115
  end
114
116
 
115
117
  def get_local_database(dirpath)
116
- filepath = File.join(dirpath, Application::INDEXFILENAME)
118
+ filepath = File.join(dirpath, Settings::INDEXFILENAME)
117
119
  # @reader.read(filepath) # FIXME
118
120
  YAML.safe_load(
119
121
  File.read(filepath),
@@ -122,7 +124,7 @@ class RepoData
122
124
  end
123
125
 
124
126
  def get_remote_database(url_repo)
125
- url_file = "#{url_repo}/#{Application::INDEXFILENAME}"
127
+ url_file = "#{url_repo}/#{Settings::INDEXFILENAME}"
126
128
  content_page = URLReader.new(url_file).read
127
129
  YAML.safe_load(
128
130
  content_page,
@@ -1,4 +1,4 @@
1
- require_relative "../application"
1
+ require_relative "../settings"
2
2
 
3
3
  class Result
4
4
  @@repoindex = Set.new
@@ -15,13 +15,14 @@ class Result
15
15
  end
16
16
 
17
17
  def id
18
- "#{reponame}#{Application::SEPARATOR}#{testname}"
18
+ "#{reponame}#{Settings::SEPARATOR}#{testname}"
19
19
  end
20
20
 
21
21
  def to_h
22
22
  {
23
23
  score: @score,
24
- id: id, reponame: @reponame,
24
+ id: id,
25
+ reponame: @reponame,
25
26
  testname: @testname,
26
27
  repoindex: repoindex
27
28
  }
@@ -0,0 +1,110 @@
1
+ require "json"
2
+ require_relative "result"
3
+ require_relative "../settings"
4
+ require_relative "../writer/format"
5
+
6
+ class Search
7
+ attr_reader :results
8
+
9
+ def initialize(database, dev)
10
+ @dev = dev
11
+ @database = database
12
+ end
13
+
14
+ def call(reponame_filter, filters)
15
+ @results = {}
16
+ @database.keys.each do |reponame|
17
+ if reponame_filter == :all || reponame.include?(reponame_filter)
18
+ search_inside_repo(reponame, filters)
19
+ end
20
+ end
21
+ sort_results
22
+ end
23
+
24
+ def show_json
25
+ list = []
26
+ @results.each do |i|
27
+ list << {
28
+ score: i[:score],
29
+ reponame: i[:reponame],
30
+ testname: i[:testname]
31
+ }
32
+ end
33
+ puts list.to_json
34
+ end
35
+
36
+ def show_screen
37
+ @results.each do |i|
38
+ @dev.write ("(x%02d) " % i[:score]), color: :white
39
+ reponame = TeutonGet::Format.colorize(i[:reponame], i[:repoindex])
40
+ @dev.writeln "#{reponame}#{Settings::SEPARATOR}#{i[:testname]}"
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def search_inside_repo(reponame, filters)
47
+ return if reponame != :all && @database[reponame].nil?
48
+
49
+ @database[reponame].each do |testname, data|
50
+ result = Result.new(
51
+ score: 0,
52
+ reponame: reponame,
53
+ testname: testname
54
+ )
55
+ if filters == :all
56
+ add_result(result)
57
+ next
58
+ end
59
+ score = 0
60
+ filters.each do |filter|
61
+ score += evaluate_test(
62
+ testname: testname,
63
+ data: data,
64
+ filter: filter
65
+ )
66
+ if score > 0
67
+ result.score = score
68
+ add_result result
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def add_result(result)
75
+ key = result.id
76
+ if @results[key].nil?
77
+ @results[key] = result
78
+ return
79
+ end
80
+ @results[key].score += result.score
81
+ end
82
+
83
+ def evaluate_test(args)
84
+ testname = args[:testname]
85
+ data = args[:data]
86
+ filter = args[:filter]
87
+ score = 0
88
+ data.each_pair do |key, value|
89
+ if value.instance_of? String
90
+ score += 1 if value.downcase.include? filter
91
+ elsif value.instance_of? Date
92
+ score += 1 if value.to_s.include? filter
93
+ elsif value.instance_of? Array
94
+ score += 1 if value.include? filter
95
+ end
96
+ end
97
+ score += 1 if testname.include? filter
98
+ score
99
+ end
100
+
101
+ def sort_results
102
+ results = []
103
+ @results.each_pair { |key, value| results += [value.to_h] }
104
+
105
+ results.sort_by! do |i|
106
+ [(Settings::MAGICNUMBER - i[:score]), i[:id]]
107
+ end
108
+ @results = results
109
+ end
110
+ end
@@ -1,42 +1,36 @@
1
- require_relative "application"
1
+ require "json"
2
+ require_relative "settings"
2
3
  require_relative "reader/yaml_reader"
3
4
  require_relative "repo/repo_data"
4
- require_relative "searcher/result"
5
- require_relative "utils/format"
5
+ require_relative "searcher/search"
6
+ require_relative "writer/format"
6
7
  require_relative "writer/terminal_writer"
7
8
 
8
9
  class Searcher
9
- def initialize(args)
10
- @dev = args[:writer]
11
-
12
- @repodata = args[:repodata]
13
- filename = @repodata.database_filename
10
+ attr_reader :results
14
11
 
15
- @reader = args[:reader]
16
- @database = @reader.read(filename)
12
+ def initialize(args)
13
+ repodata = args[:repodata]
14
+ filename = repodata.database_filename
15
+ reader = args[:reader]
16
+ database = reader.read(filename)
17
17
 
18
- @results = {}
18
+ dev = args[:writer]
19
+ @search = Search.new(database, dev)
19
20
  end
20
21
 
21
- def self.new_by_default
22
+ def self.default
22
23
  Searcher.new(
23
24
  writer: TerminalWriter.new,
24
- repodata: RepoData.new_by_default,
25
+ repodata: RepoData.default,
25
26
  reader: YamlReader.new
26
27
  )
27
28
  end
28
29
 
29
30
  def get(input)
30
31
  reponame_filter, filters = parse_input(input)
31
- search_inside(reponame_filter, filters)
32
- end
33
-
34
- def show_result
35
- @results.each do |i|
36
- @dev.write ("(x%02d) " % i[:score]), color: :white
37
- reponame = TeutonGet::Format.colorize(i[:reponame], i[:repoindex])
38
- @dev.writeln "#{reponame}#{Application::SEPARATOR}#{i[:testname]}"
39
- end
32
+ @search.call(reponame_filter, filters)
33
+ @search
40
34
  end
41
35
 
42
36
  private
@@ -44,7 +38,7 @@ class Searcher
44
38
  def parse_input(input)
45
39
  reponame_filter = :all
46
40
  filter = :all
47
- options = input.split(Application::SEPARATOR)
41
+ options = input.split(Settings::SEPARATOR)
48
42
  if options.size == 1
49
43
  reponame_filter = :all
50
44
  filter = options[0]
@@ -63,82 +57,4 @@ class Searcher
63
57
  end
64
58
  [reponame_filter, filters]
65
59
  end
66
-
67
- def search_inside(reponame_filter, filters)
68
- @results = {}
69
- if reponame_filter == :all
70
- @database.keys.each { |reponame| search_inside_repo(reponame, filters) }
71
- else
72
- @database.keys.each do |reponame|
73
- search_inside_repo(reponame, filters) if reponame.include? reponame_filter
74
- end
75
- end
76
- sort_results
77
- end
78
-
79
- def search_inside_repo(reponame, filters)
80
- return if reponame != :all && @database[reponame].nil?
81
-
82
- @database[reponame].each do |testname, data|
83
- result = Result.new(
84
- score: 0,
85
- reponame: reponame,
86
- testname: testname
87
- )
88
- if filters == :all
89
- add_result(result)
90
- next
91
- end
92
- score = 0
93
- filters.each do |filter|
94
- score += evaluate_test(
95
- testname: testname,
96
- data: data,
97
- filter: filter
98
- )
99
- if score > 0
100
- result.score = score
101
- add_result result
102
- end
103
- end
104
- end
105
- end
106
-
107
- def evaluate_test(args)
108
- testname = args[:testname]
109
- data = args[:data]
110
- filter = args[:filter]
111
-
112
- score = 0
113
- data.each_pair do |key, value|
114
- if value.instance_of? String
115
- score += 1 if value.downcase.include? filter
116
- elsif value.instance_of? Date
117
- score += 1 if value.to_s.include? filter
118
- elsif value.instance_of? Array
119
- score += 1 if value.include? filter
120
- end
121
- end
122
- score += 1 if testname.include? filter
123
- score
124
- end
125
-
126
- def add_result(result)
127
- key = result.id
128
- if @results[key].nil?
129
- @results[key] = result
130
- return
131
- end
132
- @results[key].score += result.score
133
- end
134
-
135
- def sort_results
136
- results = []
137
- @results.each_pair { |key, value| results += [value.to_h] }
138
-
139
- results.sort_by! do |i|
140
- [(Application::MAGICNUMBER - i[:score]), i[:id]]
141
- end
142
- @results = results
143
- end
144
60
  end
@@ -1,39 +1,40 @@
1
- require "singleton"
2
- require_relative "application/environment"
3
-
4
- class Application
5
- include Singleton
6
-
1
+ class Settings
7
2
  CONFIGFILE = "repos.ini"
8
3
  INDEXFILENAME = "tt-repo.yaml"
9
4
  INFOFILENAME = "tt-info.yaml"
10
5
  MAGICNUMBER = 999
11
6
  SEPARATOR = ":"
12
7
 
13
- def initialize
14
- @env = Environment.new
15
- init_params
16
- end
17
-
18
- def get(key)
8
+ def self.get(key)
19
9
  return @env.get(key) if key.instance_of? String
20
10
 
21
11
  @params[key] || "NODATA"
22
12
  end
23
13
 
24
- private
14
+ class Environment
15
+ def initialize(reader = nil)
16
+ @env = ENV
17
+ end
25
18
 
26
- def init_params
19
+ def get(key)
20
+ @env[key]
21
+ end
22
+ end
23
+
24
+ def self.init_params
27
25
  @params = {}
28
26
  home = get("HOME")
29
27
  config_dirpath = File.join(home, ".config", "teuton")
30
28
  @params[:config_dirpath] = config_dirpath
31
29
 
32
- filename = Application::CONFIGFILE
30
+ filename = CONFIGFILE
33
31
  config_filepath = File.join(config_dirpath, filename)
34
32
  @params[:config_filepath] = config_filepath
35
33
 
36
34
  cache_dirpath = File.join(config_dirpath, "cache")
37
35
  @params[:cache_dirpath] = cache_dirpath
38
36
  end
37
+
38
+ @env = Environment.new
39
+ init_params
39
40
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "repo/repo_data"
4
+ require_relative "searcher"
5
+ require "json/pure"
6
+
7
+ class ShowInfo
8
+ def initialize
9
+ @repo_data = RepoData.default
10
+ end
11
+
12
+ def call(testid, options)
13
+ testinfo = get_testinfo(testid)
14
+ if options["format"] == "json"
15
+ puts testinfo.to_json
16
+ else
17
+ @repo_data.show_testinfo(testinfo)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def get_testinfo(testid)
24
+ testinfo = @repo_data.get_info(testid)
25
+
26
+ if testinfo == {}
27
+ results = Searcher.default.get(testid).results
28
+ if results.size.zero?
29
+ puts "No results!"
30
+ exit 1
31
+ elsif results.size == 1
32
+ testid = results[0][:id]
33
+ testinfo = @repo_data.get_info(testid)
34
+ exit 1 if testinfo == {}
35
+ else
36
+ results.each { |i| puts "* #{i[:id]}" }
37
+ puts "#{results.size} results!"
38
+ exit 1
39
+ end
40
+ end
41
+
42
+ testinfo
43
+ end
44
+ end
@@ -1,6 +1,6 @@
1
- module Version
1
+ module TeutonGet
2
2
  NAME = "teuton-get"
3
3
  EXECUTABLE = "teutonget"
4
- VERSION = "0.2.7"
4
+ VERSION = "0.3.0"
5
5
  HOMEPAGE = "https://github.com/teuton-software/#{NAME}"
6
6
  end
@@ -0,0 +1,48 @@
1
+ require "colorize"
2
+
3
+ module TeutonGet
4
+ class Format
5
+ COLORS = [:light_blue, :light_magenta, :light_cyan, :red, :green, :yellow]
6
+
7
+ def self.disable
8
+ String.disable_colorization = true
9
+ end
10
+
11
+ def self.colorize(text = "", option = nil)
12
+ return text if option.nil?
13
+ color = if option.instance_of? Integer
14
+ if option < COLORS.size
15
+ COLORS[option]
16
+ else
17
+ COLORS[option - COLOR.size]
18
+ end
19
+ elsif option.instance_of? Symbol
20
+ option
21
+ else
22
+ :silver
23
+ end
24
+ text.colorize(color)
25
+ end
26
+ end
27
+ end
28
+
29
+ # class MyColor
30
+ # COLORS = {
31
+ # black: 30, red: 31, green: 32, yellow: 33,
32
+ # blue: 34, violet: 35, cyan: 36, white: 37
33
+ # }
34
+ #
35
+ # def color(code)
36
+ # color = COLORS[code]
37
+ # if color.nil?
38
+ # color = COLORS[:violet]
39
+ # puts "[WARN] MyColor: unkown value color #{code}"
40
+ # end
41
+ #
42
+ # if code == :white
43
+ # "\e[%dm#{@text}\e[0m" % color
44
+ # else
45
+ # "\e[%d;1m#{@text}\e[0m" % color
46
+ # end
47
+ # end
48
+ # end
@@ -1,8 +1,14 @@
1
1
  require "tty-table"
2
2
  require_relative "writer"
3
- require_relative "../utils/format"
3
+ require_relative "format"
4
4
 
5
5
  class TerminalWriter < Writer
6
+ attr_accessor :quiet
7
+
8
+ def initialize
9
+ @quiet = false
10
+ end
11
+
6
12
  def write(text = "", args = {})
7
13
  print TeutonGet::Format.colorize(text, args[:color])
8
14
  end
@@ -13,7 +19,6 @@ class TerminalWriter < Writer
13
19
 
14
20
  def write_table(rows)
15
21
  table = TTY::Table.new(rows)
16
- # puts table.render(:basic)
17
22
  puts table.render(:ascii)
18
23
  end
19
24
  end
data/lib/teuton-get.rb CHANGED
@@ -1,50 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "teuton-get/downloader"
1
4
  require_relative "teuton-get/repo/local_info"
2
5
  require_relative "teuton-get/repo/local_repo"
3
6
  require_relative "teuton-get/repo/repo_config"
4
7
  require_relative "teuton-get/repo/repo_data"
5
8
  require_relative "teuton-get/searcher"
6
- require_relative "teuton-get/downloader"
9
+ require_relative "teuton-get/show_info"
7
10
 
8
11
  module TeutonGet
9
- # Create metadata for local user teuton test
10
12
  def self.create_info(testpath)
11
- LocalInfo.new.user_create(testpath)
13
+ # Create metadata for local user teuton test
14
+ LocalInfo.new.user_created(testpath)
12
15
  end
13
16
 
14
- # Create metadata for local user teuton repository
15
17
  def self.create_repo(dirpath)
16
- LocalRepo.new_by_default.create(dirpath)
18
+ # Create metadata for local user teuton repository
19
+ LocalRepo.default.create(dirpath)
17
20
  end
18
21
 
19
- # Download remote teuton test
20
- def self.download(test_id, options)
21
- Downloader.new.run(test_id)
22
+ def self.download(...)
23
+ # Download teuton test from remote
24
+ Downloader.new.run(...)
22
25
  end
23
26
 
24
- # Create Teuton Repo config file
25
27
  def self.init
26
- RepoConfig.new_by_default.create
28
+ # Create Teuton Repo config file
29
+ RepoConfig.default.create
27
30
  refresh # Auto repo refresh
28
31
  end
29
32
 
30
- # Refresh Teuton Repo Data
31
33
  def self.refresh
32
- RepoData.new_by_default.refresh
34
+ # Refresh Teuton Repo Data
35
+ RepoData.default.refresh
33
36
  end
34
37
 
35
- def self.show_repo_list
36
- RepoConfig.new_by_default.show_list
38
+ def self.show_repo_list(...)
39
+ RepoConfig.default.show_list(...)
37
40
  end
38
41
 
39
- def self.show_info(test_id)
40
- repo_data = RepoData.new_by_default
41
- info = repo_data.get(test_id)
42
- repo_data.show_testinfo(info) unless info == {}
42
+ def self.show_info(...)
43
+ ShowInfo.new.call(...)
43
44
  end
44
45
 
45
- def self.search(filter)
46
- searcher = Searcher.new_by_default
47
- searcher.get(filter)
48
- searcher.show_result
46
+ def self.search(filter, options)
47
+ searcher = Searcher.default
48
+ search = searcher.get(filter)
49
+ exit 1 if search.results.size.zero?
50
+
51
+ if options["format"] == "json"
52
+ search.show_json
53
+ else
54
+ search.show_screen
55
+ end
49
56
  end
50
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teuton-get
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-26 00:00:00.000000000 Z
11
+ date: 2023-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inifile
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json_pure
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: tty-progressbar
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -117,8 +131,6 @@ files:
117
131
  - docs/repo.md
118
132
  - docs/settings.md
119
133
  - lib/teuton-get.rb
120
- - lib/teuton-get/application.rb
121
- - lib/teuton-get/application/environment.rb
122
134
  - lib/teuton-get/cli.rb
123
135
  - lib/teuton-get/downloader.rb
124
136
  - lib/teuton-get/files/repos.ini
@@ -134,9 +146,12 @@ files:
134
146
  - lib/teuton-get/repo/repo_data.rb
135
147
  - lib/teuton-get/searcher.rb
136
148
  - lib/teuton-get/searcher/result.rb
137
- - lib/teuton-get/utils/format.rb
149
+ - lib/teuton-get/searcher/search.rb
150
+ - lib/teuton-get/settings.rb
151
+ - lib/teuton-get/show_info.rb
138
152
  - lib/teuton-get/version.rb
139
153
  - lib/teuton-get/writer/file_writer.rb
154
+ - lib/teuton-get/writer/format.rb
140
155
  - lib/teuton-get/writer/null_writer.rb
141
156
  - lib/teuton-get/writer/terminal_writer.rb
142
157
  - lib/teuton-get/writer/writer.rb
@@ -1,9 +0,0 @@
1
- class Environment
2
- def initialize(reader = nil)
3
- @env = ENV
4
- end
5
-
6
- def get(key)
7
- @env[key]
8
- end
9
- end
@@ -1,23 +0,0 @@
1
- require "colorize"
2
-
3
- module TeutonGet
4
- module Format
5
- COLORS = [:light_blue, :light_magenta, :light_cyan, :red, :green, :yellow]
6
-
7
- def self.colorize(text = "", option = nil)
8
- return text if option.nil?
9
- color = if option.instance_of? Integer
10
- if option < COLORS.size
11
- COLORS[option]
12
- else
13
- COLORS[option - COLOR.size]
14
- end
15
- elsif option.instance_of? Symbol
16
- option
17
- else
18
- :silver
19
- end
20
- text.colorize(color)
21
- end
22
- end
23
- end