justprep 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/justprep/common/constants.crb +3 -1
- data/lib/justprep/common/error_messages.crb +22 -0
- data/lib/justprep/common/generate_module_recipes.crb +27 -0
- data/lib/justprep/common/include_content_from.crb +24 -0
- data/lib/justprep/common/replacement_for_module_line.crb +50 -0
- data/lib/justprep/crystal_methods.rb +8 -0
- data/lib/justprep.rb +37 -27
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5215db017617c8b34a0e8db31b2d2f0e2db2d59c0600671347fdad324ebad83
|
4
|
+
data.tar.gz: b8d16fec5e8898ed0c8154cc1856c83f2b8419d93c1f56e758f95291bff48fde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bae352f6da8c9b2b1f3a174f64f695485373225db830be20694688e02cc7368aab9e5548862c5e2e24d8ee985eef7f09b20bf674cee6ac85217418958af541e1
|
7
|
+
data.tar.gz: 50d4c6fd1f70c4e042e07d948fb0561e43e0788f73d277d54476e2cbbe9c4587fe4686b69262b7a7eb3d53494146f1a1516f0b3d9925651887d67415e568e73a
|
@@ -1,5 +1,7 @@
|
|
1
|
-
VERSION = "1.2.
|
1
|
+
VERSION = "1.2.3"
|
2
2
|
|
3
3
|
JUSTPREP_FILENAME_IN = ENV.fetch("JUSTPREP_FILENAME_IN", "main.just")
|
4
4
|
JUSTPREP_FILENAME_OUT = ENV.fetch("JUSTPREP_FILENAME_OUT", "justfile")
|
5
5
|
JUSTPREP_KEYWORDS = ENV.fetch("JUSTPREP_KEYWORDS", "import include require with").split
|
6
|
+
|
7
|
+
JUSTPREP_MODULE_KEYWORD = ENV.fetch("JUSTPREP_MODULE_KEYWORD", "module")
|
@@ -18,6 +18,11 @@ def error_file_does_not_exist(line_number, a_line)
|
|
18
18
|
STDERR.print (" "*line_out.size)+"|"
|
19
19
|
|
20
20
|
x = a_line.index(" ")
|
21
|
+
|
22
|
+
if a_line.starts_with?(JUSTPREP_MODULE_KEYWORD)
|
23
|
+
x = a_line.index(" ", x.nil? ? 0 : x + 1) # because Crystal thinks x could be nil
|
24
|
+
end
|
25
|
+
|
21
26
|
begin_filename = x.nil? ? a_line.size + 2 : x + 2
|
22
27
|
end_filename = a_line.size
|
23
28
|
len_filename = end_filename - begin_filename + 1
|
@@ -29,3 +34,20 @@ def error_file_does_not_exist(line_number, a_line)
|
|
29
34
|
|
30
35
|
return nil
|
31
36
|
end
|
37
|
+
|
38
|
+
|
39
|
+
def error_syntax(line_number, a_line)
|
40
|
+
STDERR.puts
|
41
|
+
STDERR.puts "ERROR: Syntax Problem"
|
42
|
+
|
43
|
+
# Crystal types thinks line_number can be nil or Int32
|
44
|
+
line_out = sprintf("% d ", line_number.nil? ? 0 : line_number)
|
45
|
+
STDERR.puts (" "*line_out.size)+"|"
|
46
|
+
STDERR.puts "#{line_out}| #{a_line}"
|
47
|
+
STDERR.print (" "*line_out.size)+"| "
|
48
|
+
STDERR.puts "^"*(a_line.size)
|
49
|
+
STDERR.puts
|
50
|
+
|
51
|
+
return nil
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# .../ruby/lib/justprep/common/generate_module_recipes.crb
|
2
|
+
|
3
|
+
# Given an Array of Strings representing the fake
|
4
|
+
# module names it returns a String to be appended
|
5
|
+
# to the generated justfile.
|
6
|
+
#
|
7
|
+
# Input:
|
8
|
+
# module_names .... Array(String) fake module names
|
9
|
+
#
|
10
|
+
# Output:
|
11
|
+
# recipes ... String
|
12
|
+
#
|
13
|
+
def generate_module_recipes(module_names)
|
14
|
+
recipes = ""
|
15
|
+
|
16
|
+
module_names.each do |mod_name|
|
17
|
+
recipes += "
|
18
|
+
|
19
|
+
# Module #{mod_name}
|
20
|
+
@#{mod_name} what='' args='':
|
21
|
+
just -f {{module_#{mod_name}}} {{what}} {{args}}
|
22
|
+
|
23
|
+
"
|
24
|
+
end
|
25
|
+
|
26
|
+
return recipes
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# .../ruby/lib/justprep/common/def include_content_from.crb
|
2
|
+
|
3
|
+
|
4
|
+
# single-level inclusion
|
5
|
+
#
|
6
|
+
# Input:
|
7
|
+
# out_file .......... A File pointer for String output
|
8
|
+
# module_filename ... String The name of the file to be included
|
9
|
+
#
|
10
|
+
# Output:
|
11
|
+
# nil .... This is a function without specific return value
|
12
|
+
#
|
13
|
+
def include_content_from(out_file, module_filename)
|
14
|
+
out_file.puts "\n# >>> #{module_filename}"
|
15
|
+
|
16
|
+
File.read_lines(module_filename).each do |m_line|
|
17
|
+
out_file.puts m_line
|
18
|
+
end
|
19
|
+
|
20
|
+
out_file.puts "# <<< #{module_filename}\n"
|
21
|
+
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# .../ruby/lig/justprep/common/replacement_for_module_line.crb
|
2
|
+
|
3
|
+
# Inserts the module_name into the Array of module_names
|
4
|
+
# Returns a string that defines the variable for the path to the module
|
5
|
+
#
|
6
|
+
# This method replaces a source line that looks like this:
|
7
|
+
#
|
8
|
+
# module aaa path/to/modules/justfile
|
9
|
+
#
|
10
|
+
# with a line that looks like this:
|
11
|
+
#
|
12
|
+
# module_aaa := "path/to/modules/justfile"
|
13
|
+
#
|
14
|
+
# where "aaa" is the module name.
|
15
|
+
#
|
16
|
+
# Limitations:
|
17
|
+
#
|
18
|
+
# module_name can not have a space. Only :alphanumberic: characters
|
19
|
+
# and the underscore character are valid.
|
20
|
+
#
|
21
|
+
# The "path/to/modules/justfile" must exist. Otherwise an error
|
22
|
+
# message is generated.
|
23
|
+
#
|
24
|
+
# Input:
|
25
|
+
# line_numer .... Integer the line number in the source file
|
26
|
+
# a_string ...... String the line from the source file
|
27
|
+
#
|
28
|
+
# Output:
|
29
|
+
# an Array(String) of size 2 where
|
30
|
+
# .first is the fake module_name
|
31
|
+
# .last is the replacement string that defines the module variable
|
32
|
+
#
|
33
|
+
def replacement_for_module_line(line_number, a_string)
|
34
|
+
parts = a_string.split(" ")
|
35
|
+
|
36
|
+
if parts.size < 3
|
37
|
+
error_syntax(line_number, a_string)
|
38
|
+
exit(1)
|
39
|
+
end
|
40
|
+
|
41
|
+
module_name = parts[1]
|
42
|
+
path_to_module = parts[2..].join(" ")
|
43
|
+
|
44
|
+
unless File.exists?(path_to_module)
|
45
|
+
error_file_does_not_exist(line_number, a_string)
|
46
|
+
exit(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
return [module_name, "module_#{module_name} := \"#{path_to_module}\""]
|
50
|
+
end
|
data/lib/justprep.rb
CHANGED
@@ -13,6 +13,11 @@
|
|
13
13
|
# JUSTPREP_FILENAME_IN ... main.just
|
14
14
|
# JUSTPREP_FILENAME_OUT ... justfile
|
15
15
|
# JUSTPREP_KEYWORDS ... 'import include require with'
|
16
|
+
# JUSTPREP_MODULE_KEYWORD . 'module'
|
17
|
+
#
|
18
|
+
# NOTE:
|
19
|
+
# JUSTPREP_KEYWORDS ** CANNOT ** include the value for
|
20
|
+
# JUSTPREP_MODULE_KEYWORD
|
16
21
|
#
|
17
22
|
|
18
23
|
IMPLEMENTATION = "Ruby"
|
@@ -34,37 +39,36 @@ load COMMON_DIR + "expand_file_path.crb"
|
|
34
39
|
load COMMON_DIR + "handle_command_line_parameters.crb"
|
35
40
|
load COMMON_DIR + "just_find_it.crb"
|
36
41
|
load COMMON_DIR + "usage.crb"
|
42
|
+
load COMMON_DIR + "generate_module_recipes.crb"
|
43
|
+
load COMMON_DIR + "replacement_for_module_line.crb"
|
44
|
+
load COMMON_DIR + "include_content_from.crb"
|
37
45
|
|
38
46
|
class Justprep
|
47
|
+
attr_accessor :module_names
|
48
|
+
|
39
49
|
def initialize
|
40
50
|
handle_command_line_parameters # may terminate the process
|
51
|
+
@module_names = []
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# Main function called from executable
|
56
|
+
def execute
|
57
|
+
if JUSTPREP_KEYWORDS.includes?(JUSTPREP_MODULE_KEYWORD)
|
58
|
+
STDERR.puts
|
59
|
+
STDERR.puts "ERROR: Environment Variable Configuration Problem"
|
60
|
+
STDERR.puts " JUSTPREP_KEYWORDS cannot include the same value"
|
61
|
+
STDERR.puts " as the JUSTPREP_MODULE_KEYWORD"
|
62
|
+
STDERR.puts
|
63
|
+
exit(1)
|
41
64
|
end
|
42
65
|
|
43
|
-
|
44
|
-
# single-level inclusion
|
45
|
-
def include_content_from(out_file, module_filename)
|
46
|
-
module_file = File.open(module_filename, "r")
|
47
|
-
|
48
|
-
out_file.puts "\n# >>> #{module_filename}"
|
49
|
-
|
50
|
-
module_file.readlines.each do |m_line|
|
51
|
-
out_file.write m_line
|
52
|
-
end
|
53
|
-
|
54
|
-
out_file.puts "# <<< #{module_filename}\n"
|
55
|
-
|
56
|
-
return nil
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
# Main function called from executable
|
61
|
-
def execute
|
62
66
|
in_filename = just_find_it
|
63
67
|
|
64
68
|
if in_filename.nil?
|
65
|
-
|
66
|
-
|
67
|
-
|
69
|
+
STDERR.puts "WARNING: JUSTPREP_FILENAME_IN Not Found: #{JUSTPREP_FILENAME_IN}"
|
70
|
+
exit(0)
|
71
|
+
end
|
68
72
|
|
69
73
|
out_filename = File.dirname(in_filename) + "/" + JUSTPREP_FILENAME_OUT
|
70
74
|
|
@@ -81,7 +85,7 @@ class Justprep
|
|
81
85
|
if 0 == parts.size
|
82
86
|
out_file.puts
|
83
87
|
next
|
84
|
-
|
88
|
+
end
|
85
89
|
|
86
90
|
# NOTE: Leading spaces are not allowed. The keywords
|
87
91
|
# MUST be complete left-justified.
|
@@ -101,16 +105,22 @@ class Justprep
|
|
101
105
|
module_filenames.each do |module_filename|
|
102
106
|
if File.exist?(module_filename)
|
103
107
|
include_content_from(out_file, module_filename)
|
104
|
-
|
108
|
+
else
|
105
109
|
error_file_does_not_exist(line_number, a_line)
|
106
|
-
|
107
|
-
|
110
|
+
exit(1)
|
111
|
+
end
|
108
112
|
end
|
113
|
+
elsif JUSTPREP_MODULE_KEYWORD == parts.first.downcase
|
114
|
+
result_array = replacement_for_module_line(line_number, a_line)
|
115
|
+
@module_names << result_array.first
|
116
|
+
out_file.puts result_array.last
|
109
117
|
else
|
110
118
|
out_file.puts a_line
|
111
119
|
end
|
112
120
|
end # in_file.readlines ...
|
113
121
|
|
122
|
+
out_file.puts generate_module_recipes(@module_names)
|
123
|
+
|
114
124
|
out_file.close
|
115
|
-
|
125
|
+
end # def
|
116
126
|
end # class Justprep
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: justprep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dewayne VanHoozer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|
@@ -53,8 +53,11 @@ files:
|
|
53
53
|
- lib/justprep/common/constants.crb
|
54
54
|
- lib/justprep/common/error_messages.crb
|
55
55
|
- lib/justprep/common/expand_file_path.crb
|
56
|
+
- lib/justprep/common/generate_module_recipes.crb
|
56
57
|
- lib/justprep/common/handle_command_line_parameters.crb
|
58
|
+
- lib/justprep/common/include_content_from.crb
|
57
59
|
- lib/justprep/common/just_find_it.crb
|
60
|
+
- lib/justprep/common/replacement_for_module_line.crb
|
58
61
|
- lib/justprep/common/usage.crb
|
59
62
|
- lib/justprep/crystal_methods.rb
|
60
63
|
- lib/justprep/version.rb
|
@@ -79,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
82
|
- !ruby/object:Gem::Version
|
80
83
|
version: '0'
|
81
84
|
requirements: []
|
82
|
-
rubygems_version: 3.3.
|
85
|
+
rubygems_version: 3.3.16
|
83
86
|
signing_key:
|
84
87
|
specification_version: 4
|
85
88
|
summary: A pre-processor for the 'just' command line utility
|