teuton 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/docs/changelog/todo.md +4 -8
  3. data/docs/changelog/v2.7.md +11 -0
  4. data/docs/diagram.md +16 -15
  5. data/docs/learn/06-cmd_check.md +3 -2
  6. data/docs/learn/21-exit_codes.md +9 -16
  7. data/lib/teuton/case/case.rb +25 -44
  8. data/lib/teuton/case/close.rb +2 -0
  9. data/lib/teuton/case/config.rb +3 -3
  10. data/lib/teuton/case/{runner.rb → deprecated/runner.rb} +14 -10
  11. data/lib/teuton/case/deprecated/utils.rb +40 -0
  12. data/lib/teuton/case/dsl/all.rb +8 -0
  13. data/lib/teuton/case/dsl/expect.rb +25 -9
  14. data/lib/teuton/case/dsl/goto.rb +10 -9
  15. data/lib/teuton/case/dsl/log.rb +1 -2
  16. data/lib/teuton/case/dsl/macro.rb +2 -2
  17. data/lib/teuton/case/dsl/send.rb +3 -8
  18. data/lib/teuton/case/execute/execute_base.rb +55 -0
  19. data/lib/teuton/case/execute/execute_local.rb +29 -0
  20. data/lib/teuton/case/execute/execute_manager.rb +56 -0
  21. data/lib/teuton/case/execute/execute_ssh.rb +90 -0
  22. data/lib/teuton/case/execute/execute_telnet.rb +56 -0
  23. data/lib/teuton/case/play.rb +6 -6
  24. data/lib/teuton/case_manager/case_manager.rb +12 -8
  25. data/lib/teuton/case_manager/check_cases.rb +14 -12
  26. data/lib/teuton/case_manager/dsl.rb +6 -8
  27. data/lib/teuton/case_manager/export_manager.rb +2 -3
  28. data/lib/teuton/case_manager/hall_of_fame.rb +9 -10
  29. data/lib/teuton/case_manager/report.rb +11 -9
  30. data/lib/teuton/case_manager/show_report.rb +4 -6
  31. data/lib/teuton/case_manager/utils.rb +2 -48
  32. data/lib/teuton/check/dsl.rb +1 -2
  33. data/lib/teuton/check/laboratory.rb +7 -7
  34. data/lib/teuton/check/show.rb +5 -8
  35. data/lib/teuton/cli.rb +10 -0
  36. data/lib/teuton/readme/dsl.rb +5 -7
  37. data/lib/teuton/readme/lang.rb +3 -2
  38. data/lib/teuton/readme/readme.rb +15 -18
  39. data/lib/teuton/report/formatter/default/array.rb +6 -5
  40. data/lib/teuton/report/formatter/default/txt.rb +1 -0
  41. data/lib/teuton/report/formatter/resume/array.rb +3 -3
  42. data/lib/teuton/report/formatter/resume/html.rb +2 -2
  43. data/lib/teuton/report/report.rb +6 -5
  44. data/lib/teuton/skeleton.rb +8 -10
  45. data/lib/teuton/{application.rb → utils/application.rb} +13 -5
  46. data/lib/teuton/utils/name_file_finder.rb +40 -45
  47. data/lib/teuton/utils/project.rb +73 -0
  48. data/lib/teuton/{result → utils/result}/result.rb +9 -7
  49. data/lib/teuton/utils/settings.rb +12 -0
  50. data/lib/teuton/utils/verbose.rb +2 -2
  51. data/lib/teuton/version.rb +1 -1
  52. data/lib/teuton.rb +18 -17
  53. metadata +19 -9
  54. data/lib/teuton/case/dsl.rb +0 -10
  55. /data/lib/teuton/{result → utils/result}/ext_array.rb +0 -0
  56. /data/lib/teuton/{result → utils/result}/ext_compare.rb +0 -0
  57. /data/lib/teuton/{result → utils/result}/ext_filter.rb +0 -0
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ##
4
- # Include Teuton DSL keywords into Laboratory class
5
3
  class Laboratory
4
+ # Include Teuton DSL keywords into Laboratory class
6
5
  def readme(_text)
7
6
  # Usefull for "teuton readme" command action.
8
7
  end
@@ -1,28 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../application"
4
- require_relative "../result/result"
3
+ require_relative "../utils/project"
4
+ require_relative "../utils/result/result"
5
5
  require_relative "show"
6
6
  require_relative "dsl"
7
7
  require_relative "builtin"
8
8
 
9
9
  def use(filename)
10
10
  filename += ".rb"
11
- app = Application.instance
12
- rbfiles = File.join(app.project_path, "**", filename)
11
+ rbfiles = File.join(Project.value[:project_path], "**", filename)
13
12
  files = Dir.glob(rbfiles)
14
13
  use = []
15
14
  files.sort.each { |f| use << f if f.include?(filename) }
16
15
  require_relative use[0]
16
+ Project.value[:uses] << use[0]
17
17
  end
18
18
 
19
19
  def group(name, &block)
20
- Application.instance.groups << {name: name, block: block}
20
+ Project.value[:groups] << {name: name, block: block}
21
21
  end
22
22
  alias task group
23
23
 
24
24
  def define_macro(name, *args, &block)
25
- Application.instance.macros[name] = {args: args, block: block}
25
+ Project.value[:macros][name] = {args: args, block: block}
26
26
  end
27
27
  alias def_macro define_macro
28
28
  alias defmacro define_macro
@@ -54,6 +54,6 @@ class Laboratory
54
54
  @sets = {}
55
55
  @hosts = {}
56
56
  @requests = [] # REVISE this
57
- @verbose = Application.instance.verbose
57
+ @verbose = Project.value[:verbose]
58
58
  end
59
59
  end
@@ -1,13 +1,9 @@
1
1
  require "terminal-table"
2
2
  require "rainbow"
3
3
 
4
- require_relative "../application"
4
+ require_relative "../utils/project"
5
5
  require_relative "../utils/configfile_reader"
6
6
 
7
- # Laboratory
8
- # * show_dsl
9
- # * show_stats
10
- # * show_config
11
7
  class Laboratory
12
8
  def show
13
9
  @verbose = true
@@ -34,9 +30,9 @@ class Laboratory
34
30
  end
35
31
 
36
32
  def process_content
37
- groups = Application.instance.groups
38
- option = Application.instance.options
39
-
33
+ groups = Project.value[:groups]
34
+ option = Project.value[:options]
35
+ @stats[:uses] = Project.value[:uses].size
40
36
  verboseln ""
41
37
  groups.each do |t|
42
38
  @stats[:groups] += 1
@@ -124,6 +120,7 @@ class Laboratory
124
120
  my_screen_table = Terminal::Table.new do |st|
125
121
  st.add_row ["DSL Stats", "Count"]
126
122
  st.add_separator
123
+ st.add_row ["Uses", @stats[:uses]]
127
124
  st.add_row ["Groups", @stats[:groups]]
128
125
  st.add_row ["Targets", @stats[:targets]]
129
126
  st.add_row ["Runs", @stats[:hosts]]
data/lib/teuton/cli.rb CHANGED
@@ -37,6 +37,16 @@ class CLI < Thor
37
37
  Teuton.check(projectpath, options)
38
38
  end
39
39
 
40
+ map ["co", "-co", "--config"] => "config"
41
+ desc "config DIRECTORY", "Suggest configuration"
42
+ long_desc <<~LONGDESC
43
+ config [OPTIONS] DIRECTORY", "Suggest configuration"
44
+ LONGDESC
45
+ def config(projectpath)
46
+ opt = {"onlyconfig" => true}
47
+ Teuton.check(projectpath, opt)
48
+ end
49
+
40
50
  map ["--readme"] => "readme"
41
51
  option :lang, type: :string
42
52
  desc "readme DIRECTORY", "Show README extracted from test contents"
@@ -1,12 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Readme
4
- # * target
5
- # * goto
6
- # * run
7
- # * expect
8
- # * unique
9
- # * log
4
+ # readme, target, goto, run
5
+ # expect,
6
+ # gett, set, unique, log
10
7
  class Readme
11
8
  def readme(text)
12
9
  if @action[:target].nil?
@@ -92,7 +89,8 @@ class Readme
92
89
  m = method.to_s
93
90
  if m[0] == "_"
94
91
  instance_eval("get(:#{m[1, m.size - 1]})", __FILE__, __LINE__)
95
- elsif not Application.instance.macros[m].nil?
92
+ # elsif not Application.instance.macros[m].nil?
93
+ elsif not Project.value[:macros][m].nil?
96
94
  puts "macro exec: #{m}"
97
95
  code = ""
98
96
  args[0].keys.each { |key| code += "set(:#{key}, '#{args[0][key]}')\n" }
@@ -1,4 +1,4 @@
1
- require_relative "../application"
1
+ require_relative "../utils/project"
2
2
 
3
3
  module Lang
4
4
  def self.get(key)
@@ -23,7 +23,8 @@ module Lang
23
23
  global: "\nParámetros globales que pueden ser modificados:\n",
24
24
  created: "\nParámetros creados durante la ejecución del reto:\n"
25
25
  }
26
- locale = Application.instance.options["lang"].downcase
26
+ # locale = Application.instance.options["lang"].downcase
27
+ locale = Project.value[:options]["lang"].downcase
27
28
  lang[locale][key]
28
29
  end
29
30
  end
@@ -1,27 +1,27 @@
1
- require_relative "../application"
1
+ require_relative "../utils/project"
2
2
  require_relative "../utils/configfile_reader"
3
- require_relative "../result/result"
3
+ require_relative "../utils/result/result"
4
4
  require_relative "../version"
5
5
  require_relative "dsl"
6
6
  require_relative "lang"
7
7
 
8
8
  def use(filename)
9
9
  filename += ".rb"
10
- app = Application.instance
11
- rbfiles = File.join(app.project_path, "**", filename)
10
+ rbfiles = File.join(Project.value[:project_path], "**", filename)
12
11
  files = Dir.glob(rbfiles)
13
12
  use = []
14
13
  files.sort.each { |f| use << f if f.include?(filename) }
15
14
  require_relative use[0]
15
+ Project.value[:uses] << use[0]
16
16
  end
17
17
 
18
18
  def define_macro(name, *args, &block)
19
19
  puts "macro: #{name}"
20
- Application.instance.macros[name] = {args: args, block: block}
20
+ Project.value[:macros][name] = {args: args, block: block}
21
21
  end
22
22
 
23
23
  def group(name, &block)
24
- Application.instance.groups << {name: name, block: block}
24
+ Project.value[:groups] << {name: name, block: block}
25
25
  end
26
26
  alias task group
27
27
 
@@ -31,16 +31,14 @@ end
31
31
  # alias_method "play", "start" # REVISE THIS
32
32
  alias play start
33
33
 
34
- # Creates README.md file from RB script file
35
34
  class Readme
35
+ # Creates README.md file from RB script file
36
36
  attr_reader :result
37
37
  attr_reader :data
38
38
 
39
- ##
40
- # Initialize Readme instance
41
- # @param script_path (String) Path to main rb file (start.rb)
42
- # @param config_path (String) Path to main config file (config.yaml)
43
39
  def initialize(script_path, config_path)
40
+ # script_path Path to main rb file (start.rb)
41
+ # config_path Path to main config file (config.yaml)
44
42
  @path = {}
45
43
  @path[:script] = script_path
46
44
  @path[:dirname] = File.dirname(script_path)
@@ -59,9 +57,9 @@ class Readme
59
57
  private
60
58
 
61
59
  def reset
62
- app = Application.instance
63
- @config = ConfigFileReader.read(app.config_path)
64
- @verbose = app.verbose
60
+ # app = Application.instance
61
+ @config = ConfigFileReader.read(Project.value[:config_path])
62
+ @verbose = Project.value[:verbose]
65
63
  @result = Result.new
66
64
  @data = {}
67
65
  @data[:macros] = []
@@ -76,7 +74,7 @@ class Readme
76
74
  end
77
75
 
78
76
  def process_content
79
- Application.instance.groups.each do |g|
77
+ Project.value[:groups].each do |g|
80
78
  @current = {name: g[:name], readme: [], actions: []}
81
79
  @data[:groups] << @current
82
80
  reset_action
@@ -89,14 +87,13 @@ class Readme
89
87
  end
90
88
 
91
89
  def show_head
92
- app = Application.instance
93
90
  puts "```"
94
- puts format(Lang.get(:testname), app.test_name)
91
+ puts format(Lang.get(:testname), Project.value[:test_name])
95
92
  puts format(Lang.get(:date), Time.now)
96
93
  puts format(Lang.get(:version), Teuton::VERSION)
97
94
  puts "```"
98
95
  puts "\n"
99
- puts "# #{app.test_name}\n"
96
+ puts "# #{Project.value[:test_name]}\n"
100
97
 
101
98
  i = 1
102
99
  unless @required_hosts.empty?
@@ -1,5 +1,5 @@
1
1
  require_relative "../base_formatter"
2
- require_relative "../../../application"
2
+ require_relative "../../../utils/project"
3
3
 
4
4
  class ArrayFormatter < BaseFormatter
5
5
  def initialize(report)
@@ -60,12 +60,14 @@ class ArrayFormatter < BaseFormatter
60
60
  target[:duration] = i[:duration]
61
61
 
62
62
  target[:command] = i[:command]
63
+ target[:output] = i[:output]
63
64
  target[:alterations] = i[:alterations]
64
65
  target[:expected] = i[:expected]
65
66
  target[:result] = i[:result]
66
67
 
67
68
  if options[:feedback] == false
68
69
  target[:command] = "*" * i[:command].size
70
+ target[:output] = "*" * i[:output].size
69
71
  target[:alterations] = "*" * i[:alterations].size
70
72
  target[:expected] = "*" * i[:expected].size
71
73
  target[:result] = "*" * i[:result].size
@@ -85,12 +87,11 @@ class ArrayFormatter < BaseFormatter
85
87
  end
86
88
 
87
89
  def build_hof_data
88
- app = Application.instance
89
90
  @data[:hall_of_fame] = {}
90
- return if app.options[:case_number] < 3
91
+ return if Project.value[:options][:case_number] < 3
91
92
 
92
93
  fame = {}
93
- app.hall_of_fame.each { |line| fame[line[0]] = line[1] }
94
+ Project.value[:hall_of_fame].each { |line| fame[line[0]] = line[1] }
94
95
  @data[:hall_of_fame] = fame
95
96
  end
96
97
 
@@ -115,6 +116,6 @@ class ArrayFormatter < BaseFormatter
115
116
  end
116
117
 
117
118
  def version
118
- Application::VERSION
119
+ Teuton::VERSION
119
120
  end
120
121
  end
@@ -91,6 +91,7 @@ class TXTFormatter < ArrayFormatter
91
91
  w " (" + Rainbow(i[:score].to_s + "/" + i[:weight].to_s).color(color) + ")\n"
92
92
  w "#{tab * 4}Description : #{i[:description]}\n"
93
93
  w "#{tab * 4}Command : #{i[:command]}\n"
94
+ w "#{tab * 4}Output : #{i[:output]}\n"
94
95
  w "#{tab * 4}Duration : #{i[:duration]} (#{i[:conn_type]})\n"
95
96
  w "#{tab * 4}Alterations : #{i[:alterations]}\n"
96
97
  w "#{tab * 4}Expected : #{i[:expected]} (#{i[:expected].class})\n"
@@ -1,4 +1,5 @@
1
1
  require_relative "../base_formatter"
2
+ require_relative "../../../utils/project"
2
3
 
3
4
  class ResumeArrayFormatter < BaseFormatter
4
5
  def initialize(report)
@@ -36,10 +37,9 @@ class ResumeArrayFormatter < BaseFormatter
36
37
  end
37
38
 
38
39
  def build_hof_data
39
- app = Application.instance
40
40
  fame = {}
41
- if app.options[:case_number] > 2
42
- app.hall_of_fame.each { |line| fame[line[0]] = line[1] }
41
+ if Project.value[:options][:case_number] > 2
42
+ Project.value[:hall_of_fame].each { |line| fame[line[0]] = line[1] }
43
43
  end
44
44
  @data[:hall_of_fame] = fame
45
45
  end
@@ -1,6 +1,6 @@
1
1
  require "erb"
2
2
  require_relative "yaml"
3
- require_relative "../../../application"
3
+ # require_relative "../../../../teuton"
4
4
 
5
5
  class ResumeHTMLFormatter < ResumeYAMLFormatter
6
6
  def initialize(report)
@@ -42,6 +42,6 @@ class ResumeHTMLFormatter < ResumeYAMLFormatter
42
42
  end
43
43
 
44
44
  def version
45
- Application::VERSION
45
+ Teuton::VERSION
46
46
  end
47
47
  end
@@ -1,4 +1,5 @@
1
- require_relative "../application"
1
+ require_relative "../utils/project"
2
+ require_relative "../utils/settings"
2
3
  require_relative "formatter/formatter"
3
4
 
4
5
  class Report
@@ -12,7 +13,8 @@ class Report
12
13
  def initialize(id = "00")
13
14
  @id = id
14
15
  @filename = "case-#{@id}"
15
- @output_dir = Application.instance.output_basedir
16
+ # @output_dir = Application.instance.output_basedir
17
+ @output_dir = Project.value[:output_basedir]
16
18
  @head = {}
17
19
  @lines = []
18
20
  @tail = {}
@@ -57,7 +59,6 @@ class Report
57
59
  # * fail_weight
58
60
  # * fail_counter
59
61
  def close
60
- app = Application.instance
61
62
  max = 0.0
62
63
  good = 0.0
63
64
  fail = 0.0
@@ -68,11 +69,11 @@ class Report
68
69
  max += i[:weight] if i[:weight].positive?
69
70
  if i[:check]
70
71
  good += i[:weight]
71
- @history += app.letter[:good]
72
+ @history += Settings.letter[:good]
72
73
  else
73
74
  fail += i[:weight]
74
75
  fail_counter += 1
75
- @history += app.letter[:bad]
76
+ @history += Settings.letter[:bad]
76
77
  end
77
78
  end
78
79
  @tail[:max_weight] = max
@@ -1,16 +1,18 @@
1
1
  require "fileutils"
2
2
  require "rainbow"
3
3
 
4
- module Skeleton
5
- def self.create(project_dir)
4
+ class Skeleton
5
+ def create(project_dir)
6
6
  project_name = File.basename(project_dir)
7
- puts "\n[INFO] Creating #{Rainbow(project_name).bright} project skeleton"
7
+ puts "\nCreating #{Rainbow(project_name).bright} project"
8
8
  source_basedir = File.dirname(__FILE__)
9
9
  create_dir project_dir
10
10
  create_main_dir_and_files(project_dir, source_basedir)
11
11
  end
12
12
 
13
- private_class_method def self.create_main_dir_and_files(project_dir, source_basedir)
13
+ private
14
+
15
+ def create_main_dir_and_files(project_dir, source_basedir)
14
16
  # Directory and files: Ruby script, Configfile, gitignore
15
17
  items = [
16
18
  {source: "files/config.yaml", target: "config.yaml"},
@@ -23,7 +25,7 @@ module Skeleton
23
25
  end
24
26
  end
25
27
 
26
- private_class_method def self.create_dir(dirpath)
28
+ def create_dir(dirpath)
27
29
  if Dir.exist? dirpath
28
30
  puts "* Exists dir! => #{Rainbow(dirpath).yellow}"
29
31
  else
@@ -36,11 +38,7 @@ module Skeleton
36
38
  end
37
39
  end
38
40
 
39
- ##
40
- # Copy file
41
- # @param source (String) Source file
42
- # @param dest (String) Dest file
43
- private_class_method def self.copyfile(source, dest)
41
+ def copyfile(source, dest)
44
42
  if File.exist? dest
45
43
  puts "* Exists file! => #{Rainbow(dest).yellow}"
46
44
  else
@@ -1,5 +1,5 @@
1
1
  require "singleton"
2
- require_relative "utils/name_file_finder"
2
+ require_relative "name_file_finder"
3
3
 
4
4
  class Application
5
5
  include Singleton
@@ -33,7 +33,11 @@ class Application
33
33
  @running_basedir = Dir.getwd
34
34
  @output_basedir = "var"
35
35
  @default = {name: "teuton", format: :txt, debug: false}
36
- @options = {"lang" => "en"}
36
+ @options = {
37
+ "lang" => "en",
38
+ "color" => true,
39
+ "panel" => false
40
+ }
37
41
  @verbose = true
38
42
 
39
43
  @global = {}
@@ -65,10 +69,14 @@ class Application
65
69
  # * Read color input option
66
70
  def add_input_params(projectpath, options)
67
71
  @options.merge! options
68
- NameFileFinder.find_filenames_for(projectpath)
69
- @options["color"] = true if @options["color"].nil?
70
72
  Rainbow.enabled = @options["color"]
71
- @options["panel"] = false if @options["panel"].nil?
73
+
74
+ finder = NameFileFinder.new(@options)
75
+ finder.find_filenames_for(projectpath)
76
+ @project_path = finder.project_path
77
+ @script_path = finder.script_path
78
+ @config_path = finder.config_path
79
+ @test_name = finder.test_name
72
80
 
73
81
  unless @options["case"].nil?
74
82
  numbers = @options["case"].split(",")
@@ -1,10 +1,24 @@
1
1
  require "rainbow"
2
2
 
3
- module NameFileFinder
3
+ class NameFileFinder
4
+ attr_reader :options
5
+ attr_reader :project_path
6
+ attr_reader :script_path
7
+ attr_reader :config_path
8
+ attr_reader :test_name
9
+
10
+ def initialize(options = {})
11
+ @options = options
12
+ @project_path = nil
13
+ @script_path = nil
14
+ @config_path = nil
15
+ @test_name = nil
16
+ end
17
+
4
18
  ##
5
19
  # Find project filenames from input project relative path
6
20
  # @param relprojectpath (String)
7
- def self.find_filenames_for(relprojectpath)
21
+ def find_filenames_for(relprojectpath)
8
22
  projectpath = File.absolute_path(relprojectpath)
9
23
 
10
24
  # Define:
@@ -20,10 +34,10 @@ module NameFileFinder
20
34
  true
21
35
  end
22
36
 
23
- ##
24
- # Find project filenames from input folder path
25
- # @param folder_path (String)
26
- def self.find_filenames_from_directory(folder_path)
37
+ private
38
+
39
+ def find_filenames_from_directory(folder_path)
40
+ # Find project filenames from input folder path
27
41
  # COMPLEX MODE: We use start.rb as main RB file
28
42
  script_path = File.join(folder_path, "start.rb")
29
43
  unless File.exist? script_path
@@ -31,38 +45,34 @@ module NameFileFinder
31
45
  exit 1
32
46
  end
33
47
 
34
- app = Application.instance
35
- app.project_path = folder_path
36
- app.script_path = script_path
37
- app.test_name = folder_path.split(File::SEPARATOR)[-1]
48
+ @project_path = folder_path
49
+ @script_path = script_path
50
+ @test_name = folder_path.split(File::SEPARATOR)[-1]
38
51
 
39
52
  find_configfilename_from_directory(folder_path)
40
53
  end
41
54
 
42
- ##
43
- # Find project config filename from input folder path
44
- # @param folder_path (String)
45
- def self.find_configfilename_from_directory(folder_path)
55
+ def find_configfilename_from_directory(folder_path)
56
+ # Find project config filename from input folder path
46
57
  # COMPLEX MODE: We use config.yaml by default
47
- app = Application.instance
48
58
  config_path = ""
49
59
 
50
- if app.options["cpath"].nil?
60
+ if options["cpath"].nil?
51
61
  config_name = "config"
52
62
  # Config name file is introduced by cname arg option from teuton command
53
- config_name = app.options["cname"] unless app.options["cname"].nil?
63
+ config_name = options["cname"] unless options["cname"].nil?
54
64
  config_path = File.join(folder_path, "#{config_name}.json")
55
65
  unless File.exist? config_path
56
66
  config_path = File.join(folder_path, "#{config_name}.yaml")
57
67
  end
58
68
  else
59
69
  # Config path file is introduced by cpath arg option from teuton command
60
- config_path = app.options["cpath"]
70
+ config_path = options["cpath"]
61
71
  end
62
- app.config_path = config_path
72
+ @config_path = config_path
63
73
  end
64
74
 
65
- def self.find_filenames_from_rb(script_path)
75
+ def find_filenames_from_rb(script_path)
66
76
  # SIMPLE MODE: We use script_path as main RB file
67
77
  # This must be fullpath to DSL script file
68
78
  if File.extname(script_path) != ".rb"
@@ -71,44 +81,29 @@ module NameFileFinder
71
81
  exit 1
72
82
  end
73
83
 
74
- app = Application.instance
75
- app.project_path = File.dirname(script_path)
76
- app.script_path = script_path
77
- app.test_name = File.basename(script_path, ".rb")
78
-
84
+ @project_path = File.dirname(script_path)
85
+ @script_path = script_path
86
+ @test_name = File.basename(script_path, ".rb")
79
87
  find_configfilenames_from_rb(script_path)
80
88
  end
81
89
 
82
- def self.find_configfilenames_from_rb(script_path)
90
+ def find_configfilenames_from_rb(script_path)
83
91
  # SIMPLE MODE: We use script_path as main RB file
84
92
  # This must be fullpath to DSL script file
85
- app = Application.instance
86
-
87
93
  config_path = ""
88
- if app.options["cpath"].nil?
94
+ if options["cpath"].nil?
89
95
  config_name = File.basename(script_path, ".rb")
90
96
  # Config name file is introduced by cname arg option from teuton command
91
- config_name = app.options["cname"] unless app.options["cname"].nil?
97
+ config_name = options["cname"] unless options["cname"].nil?
92
98
 
93
- config_path = File.join(app.project_path, config_name + ".json")
99
+ config_path = File.join(@project_path, config_name + ".json")
94
100
  unless File.exist? config_path
95
- config_path = File.join(app.project_path, config_name + ".yaml")
101
+ config_path = File.join(@project_path, config_name + ".yaml")
96
102
  end
97
103
  else
98
104
  # Config path file is introduced by cpath arg option from teuton command
99
- config_path = app.options["cpath"]
105
+ config_path = options["cpath"]
100
106
  end
101
- app.config_path = config_path
102
- end
103
-
104
- def self.verboseln(text)
105
- verbose(text + "\n")
106
- end
107
-
108
- def self.verbose(text)
109
- return unless Application.instance.verbose
110
- return if Application.instance.options["quiet"]
111
-
112
- print text
107
+ @config_path = config_path
113
108
  end
114
109
  end
@@ -0,0 +1,73 @@
1
+ # Development in progress...
2
+
3
+ require_relative "name_file_finder"
4
+
5
+ class Project
6
+ def self.init
7
+ @project = {}
8
+ @project[:running_basedir] = Dir.getwd
9
+ @project[:output_basedir] = "var"
10
+ @project[:name] = "teuton"
11
+ @project[:format] = :txt
12
+ @project[:debug] = false
13
+ @project[:options] = {
14
+ "color" => true,
15
+ "lang" => "en",
16
+ "panel" => false,
17
+ "quiet" => false
18
+ }
19
+ @project[:verbose] = true
20
+ @project[:global] = {} # Hash of Global configuration params
21
+ @project[:ialias] = {} # Hash of Internal alias
22
+ @project[:macros] = {} # Hash of macros
23
+ @project[:groups] = [] # Array of groups
24
+ @project[:uses] = [] # TODO: Array of files used
25
+ @project[:hall_of_fame] = []
26
+ end
27
+
28
+ def self.value
29
+ @project
30
+ end
31
+
32
+ init
33
+
34
+ def self.debug?
35
+ value[:debug]
36
+ end
37
+
38
+ def self.name
39
+ value[:name]
40
+ end
41
+
42
+ def self.quiet?
43
+ return true if value[:options]["quiet"]
44
+ return true unless value[:verbose]
45
+
46
+ false
47
+ end
48
+
49
+ def self.verbose
50
+ value[:verbose]
51
+ end
52
+
53
+ ##
54
+ # Preprocess input options:
55
+ # * Convert input case options String to an Array of integers
56
+ # * Read color input option
57
+ def self.add_input_params(projectpath, options)
58
+ value[:options].merge! options
59
+ Rainbow.enabled = value[:options]["color"]
60
+
61
+ finder = NameFileFinder.new(value[:options])
62
+ finder.find_filenames_for(projectpath)
63
+ value[:project_path] = finder.project_path
64
+ value[:script_path] = finder.script_path
65
+ value[:config_path] = finder.config_path
66
+ value[:test_name] = finder.test_name
67
+
68
+ unless value[:options]["case"].nil?
69
+ numbers = value[:options]["case"].split(",")
70
+ value[:options]["case"] = numbers.collect!(&:to_i)
71
+ end
72
+ end
73
+ end