skap 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16e74f93e2cb2c5bfb6ec42565f0ee3a276f6d134a63418a98328a259141272e
4
- data.tar.gz: a00a345fb79bd667ecde44d7b62fc8933f0f6e131185a740a6a6e30afd78e047
3
+ metadata.gz: 64c306b147d5300884174c3d2a4d6c6c51aec457b254304ec8d5d5df1be6b5f4
4
+ data.tar.gz: a652962929effff42642bcbe13f35c06c6cd787827377ce2e98d8c1909d0e23f
5
5
  SHA512:
6
- metadata.gz: '0908fffd649481ec79c9f772585beacf0b327ff6614dd2da60c9090c77876bb67cd0ec0d4f014b2b0eada4ddc1141c43c9f330c38e612fcfd03bcfa35f1d1459'
7
- data.tar.gz: 27c06e31d15c05c3b311854f26f0f01eb8adb23487b79b9c8d8d426b09799d75720a5dd9c7bcaf9e11f33ae4f90c92f4b4e812c5c09529935cb2540fa0a7d248
6
+ metadata.gz: d70210fe51ee5f0fa6f88683679f6995b2d39c07065be89a4bc16499658339e98313940e08b3d4814e1699fab9c043f8bf1ec3e834c162155e535562e145711b
7
+ data.tar.gz: ecfca637dbb0deb6f68c90e4dfcbffc08a4fc619bd87f7df1d754e7846935a730844c45ea6da7177dec3349912bdd34360b6b737dd39b41253835a09577c1b1a
data/lib/skap/cli/help.rb CHANGED
@@ -1,58 +1,57 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Skap
4
- module CLI::Help
5
- include Command
6
- extend self
3
+ # CLI command with help message.
4
+ module Skap::CLI::Help
5
+ include Skap::Command
6
+ extend self
7
7
 
8
- # @return [void]
9
- def start
10
- menu = Files::Menu.new
8
+ # @return [void]
9
+ def start
10
+ menu = Skap::Files::Menu.new
11
11
 
12
- puts "Usage:", ""
12
+ puts "Usage:", ""
13
13
 
14
- show_menu(menu, $DEFAULT_OUTPUT.winsize.last)
15
- end
16
-
17
- private
14
+ show_menu(menu, $DEFAULT_OUTPUT.winsize.last)
15
+ end
18
16
 
19
- # @param text [String]
20
- # @param indent [String]
21
- # @param max_width [Integer]
22
- # @return [void]
23
- def output_menu_item_text(text, indent, max_width)
24
- res = []
17
+ private
25
18
 
26
- if text.is_a?(Array)
27
- text.each { |paragraph| res += StringUtils.break_by_words(paragraph, max_width) }
28
- else
29
- res += StringUtils.break_by_words(text, max_width)
30
- end
19
+ # @param text [String]
20
+ # @param indent [String]
21
+ # @param max_width [Integer]
22
+ # @return [void]
23
+ def output_menu_item_text(text, indent, max_width)
24
+ res = []
31
25
 
32
- res.each { |line| puts "#{indent}#{line}" }
26
+ if text.is_a?(Array)
27
+ text.each { |paragraph| res += Skap::StringUtils.break_by_words(paragraph, max_width) }
28
+ else
29
+ res += Skap::StringUtils.break_by_words(text, max_width)
33
30
  end
34
31
 
35
- # @param menu [Files::Menu]
36
- # @param width [Integer]
37
- # @return [void]
38
- def show_menu(menu, width) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
39
- section_indent = " " * 4
40
- command_indent = " " * 8
41
- within_section = width - 4
42
- within_command = width - 8
32
+ res.each { |line| puts "#{indent}#{line}" }
33
+ end
34
+
35
+ # @param menu [Files::Menu]
36
+ # @param width [Integer]
37
+ # @return [void]
38
+ def show_menu(menu, width) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
39
+ section_indent = " " * 4
40
+ command_indent = " " * 8
41
+ within_section = width - 4
42
+ within_command = width - 8
43
43
 
44
- menu.each do |item|
45
- puts item["cmd"]
44
+ menu.each do |item|
45
+ puts item["cmd"]
46
46
 
47
- output_menu_item_text(item["text"], section_indent, within_section) if item.key?("text")
47
+ output_menu_item_text(item["text"], section_indent, within_section) if item.key?("text")
48
48
 
49
- next unless item.key?("children")
49
+ next unless item.key?("children")
50
50
 
51
- item["children"].each do |subitem|
52
- [*subitem["cmd"]].each { |cmd| puts "#{section_indent}#{cmd}" }
51
+ item["children"].each do |subitem|
52
+ [*subitem["cmd"]].each { |cmd| puts "#{section_indent}#{cmd}" }
53
53
 
54
- output_menu_item_text(subitem["text"], command_indent, within_command)
55
- end
54
+ output_menu_item_text(subitem["text"], command_indent, within_command)
56
55
  end
57
56
  end
58
57
  end
data/lib/skap/cli/init.rb CHANGED
@@ -1,23 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Skap
4
- module CLI::Init
5
- include Command
6
- extend self
3
+ # CLI command for repository initialization.
4
+ module Skap::CLI::Init
5
+ include Skap::Command
6
+ extend self
7
7
 
8
- # @param dir [String]
9
- # @param args [Array<String>]
10
- # @return [void]
11
- def start(dir, args)
12
- assert_empty_options(args)
8
+ # @param dir [String]
9
+ # @param args [Array<String>]
10
+ # @return [void]
11
+ def start(dir, args)
12
+ assert_empty_options(args)
13
13
 
14
- FileUtils.mkdir_p(dir)
14
+ FileUtils.mkdir_p(dir)
15
15
 
16
- shell("git init", dir:)
17
- shell("echo '---\n' > #{Files::Sources.file_name}", dir:)
18
- shell("echo '---\n' > #{Files::Versions.file_name}", dir:)
16
+ shell("git init", dir:)
17
+ shell("echo '---\n' > #{Skap::Files::Sources.file_name}", dir:)
18
+ shell("echo '---\n' > #{Skap::Files::Versions.file_name}", dir:)
19
19
 
20
- puts "Git repo initialized in #{dir}"
21
- end
20
+ puts "Git repo initialized in #{dir}"
22
21
  end
23
22
  end
@@ -1,59 +1,61 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Skap
4
- module CLI::Sources
5
- include Command
6
- extend self
7
-
8
- # @param command [String]
9
- # @param args [Array<String>]
10
- # @return [void]
11
- def start(command, args)
12
- assert_cwd
13
-
14
- case command
15
- when "add" then add(*args)
16
- when "delete" then delete(*args)
17
- when "update" then update(*args)
18
- else
19
- raise ArgumentError, "Unknown command: #{command}"
20
- end
3
+ # CLI command for managing sources list.
4
+ module Skap::CLI::Sources
5
+ include Skap::Command
6
+ extend self
7
+
8
+ # @param command [String]
9
+ # @param args [Array<String>]
10
+ # @return [void]
11
+ def start(command, args)
12
+ assert_cwd
13
+
14
+ case command
15
+ when "add" then add(*args)
16
+ when "delete" then delete(*args)
17
+ when "update" then update(*args)
18
+ else
19
+ raise ArgumentError, "Unknown command: #{command}"
21
20
  end
21
+ end
22
22
 
23
- private
23
+ private
24
24
 
25
- # @param dir [String]
26
- # @param repo [String]
27
- # @param branch [String]
28
- # @param rest [Array<String>]
29
- # @return [void]
30
- def add(dir, repo, branch, *rest)
31
- assert_empty_options(rest)
25
+ # @param dir [String]
26
+ # @param repo [String]
27
+ # @param branch [String]
28
+ # @param rest [Array<String>]
29
+ # @return [void]
30
+ def add(dir, repo, branch, *rest)
31
+ assert_empty_options(rest)
32
32
 
33
- return unless shell("git submodule add -b #{branch} --depth 3 -- #{repo} #{dir}")
33
+ return unless shell("git submodule add -b #{branch} --depth 3 -- #{repo} #{dir}")
34
34
 
35
- sources_data = load_file(SOURCES)
36
- sources_data[dir] = {"file-extensions" => [], "ignored" => [], "indexed" => []}
35
+ Skap::Files::Sources.new.add_source(dir)
36
+ end
37
37
 
38
- sources_data = sources_data.sort_by(&:first).to_h
39
- File.write(SOURCES, Psych.dump(sources_data, line_width: 100))
40
- end
38
+ # @param dir [String]
39
+ # @param rest [Array<String>]
40
+ # @return [void]
41
+ def delete(dir, *rest)
42
+ assert_empty_options(rest)
41
43
 
42
- # @param dir [String]
43
- # @param rest [Array<String>]
44
- # @return [void]
45
- def delete(dir, *rest)
46
- assert_empty_options(rest)
44
+ shell("git submodule deinit -f -- #{dir} && git rm -f #{dir} && rm -rf .git/modules/#{dir}")
47
45
 
48
- shell("git submodule deinit -f -- #{dir} && git rm -f #{dir} && rm -rf .git/modules/#{dir}")
49
- end
46
+ Skap::Files::Sources.new.delete_source(dir)
47
+ end
50
48
 
51
- # @param dirs [Array<String>]
52
- # @return [void]
53
- def update(*dirs)
54
- path_arg = dirs.empty? ? "" : "-- #{dirs.join(" ")}"
49
+ # @param dirs [Array<String>]
50
+ # @return [void]
51
+ def update(*dirs)
52
+ path_arg = dirs.empty? ? "" : "-- #{dirs.join(" ")}"
55
53
 
56
- shell("git submodule update --checkout --single-branch --recursive #{path_arg}")
57
- end
54
+ commands = [
55
+ "git submodule init",
56
+ "git submodule update --checkout --single-branch --recursive #{path_arg}",
57
+ ]
58
+
59
+ shell(commands.join(" && "))
58
60
  end
59
61
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # CLI command for showing Skap version.
4
+ module Skap::CLI::Version
5
+ include Skap::Command
6
+ extend self
7
+
8
+ # @return [void]
9
+ def start
10
+ puts "Skap, v#{Skap::VERSION}"
11
+ end
12
+ end
@@ -1,175 +1,174 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Skap
4
- module CLI::Works
5
- include Command
6
- extend self
7
-
8
- # @param command [String]
9
- # @param args [Array<String>]
10
- # @return [void]
11
- def start(command, args) # rubocop:disable Metrics/MethodLength
12
- assert_cwd
13
-
14
- case command
15
- when "covered" then covered(*args)
16
- when "ignored" then ignored(*args)
17
- when "publish" then publish(*args)
18
- when "outdated" then outdated(*args)
19
- when "uncovered" then uncovered(*args)
20
- when "unknown" then unknown(*args)
21
- else
22
- raise ArgumentError, "Unknown command: #{command}"
23
- end
3
+ # CLI command for managing works (files based on sources).
4
+ module Skap::CLI::Works
5
+ include Skap::Command
6
+ extend self
7
+
8
+ # @param command [String]
9
+ # @param args [Array<String>]
10
+ # @return [void]
11
+ def start(command, args) # rubocop:disable Metrics/MethodLength
12
+ assert_cwd
13
+
14
+ case command
15
+ when "covered" then covered(*args)
16
+ when "ignored" then ignored(*args)
17
+ when "publish" then publish(*args)
18
+ when "outdated" then outdated(*args)
19
+ when "uncovered" then uncovered(*args)
20
+ when "unknown" then unknown(*args)
21
+ else
22
+ raise ArgumentError, "Unknown command: #{command}"
24
23
  end
24
+ end
25
25
 
26
- private
26
+ private
27
27
 
28
- # @param path_patterns_as_hash [Hash<String, Array<String>>]
29
- # @return [Array<String>]
30
- def collect_files(path_patterns_as_hash)
31
- flatten_path_patterns(path_patterns_as_hash).flat_map do |path_pattern|
32
- find_files_by_pattern(path_pattern)
33
- end
28
+ # @param path_patterns_as_hash [Hash<String, Array<String>>]
29
+ # @return [Array<String>]
30
+ def collect_files(path_patterns_as_hash)
31
+ flatten_path_patterns(path_patterns_as_hash).flat_map do |path_pattern|
32
+ find_files_by_pattern(path_pattern)
34
33
  end
34
+ end
35
35
 
36
- # @param path [String]
37
- # @return [String]
38
- def commit_sha(path)
39
- dir, file = File.split(path)
40
-
41
- shell("git rev-parse HEAD -- #{file}", dir:).split("\n").first
42
- end
36
+ # @param path [String]
37
+ # @return [String]
38
+ def commit_sha(path)
39
+ dir, file = File.split(path)
43
40
 
44
- # @param dirs [Array<String>]
45
- # @return [void]
46
- def covered(*dirs)
47
- sources = Files::Sources.new.extract("indexed", dir_names_without_slash(dirs))
41
+ shell("git rev-parse HEAD -- #{file}", dir:).split("\n").first
42
+ end
48
43
 
49
- puts (Files::Versions.new.covered_sources & collect_files(sources)).sort
50
- end
44
+ # @param dirs [Array<String>]
45
+ # @return [void]
46
+ def covered(*dirs)
47
+ sources = Skap::Files::Sources.new.extract("indexed", dir_names_without_slash(dirs))
51
48
 
52
- # @param dirs [Array<String>]
53
- # @return [Array<String>]
54
- def dir_names_with_slash(dirs)
55
- dirs.map { |x| x.end_with?("/") ? x : "#{x}/" }
56
- end
49
+ puts (Skap::Files::Versions.new.covered_sources & collect_files(sources)).sort
50
+ end
57
51
 
58
- # @param dirs [Array<String>]
59
- # @return [Array<String>]
60
- def dir_names_without_slash(dirs)
61
- dirs.map { |x| x.end_with?("/") ? x.chop : x }
62
- end
52
+ # @param dirs [Array<String>]
53
+ # @return [Array<String>]
54
+ def dir_names_with_slash(dirs)
55
+ dirs.map { |x| x.end_with?("/") ? x : "#{x}/" }
56
+ end
63
57
 
64
- # @param path_pattern [String]
65
- # @return [Array<String>]
66
- def find_files_by_pattern(path_pattern)
67
- if path_pattern.include?("*")
68
- result = Dir.glob(path_pattern, base: CURRENT_DIR)
69
- raise ArgumentError, "No files found for path pattern \"#{path_pattern}\"" if result.empty?
58
+ # @param dirs [Array<String>]
59
+ # @return [Array<String>]
60
+ def dir_names_without_slash(dirs)
61
+ dirs.map { |x| x.end_with?("/") ? x.chop : x }
62
+ end
70
63
 
71
- result
72
- else
73
- raise ArgumentError, "File \"#{path_pattern}\" doesn't exist" if !File.exist?(path_pattern)
64
+ # @param path_pattern [String]
65
+ # @return [Array<String>]
66
+ def find_files_by_pattern(path_pattern)
67
+ if path_pattern.include?("*")
68
+ result = Dir.glob(path_pattern, base: CURRENT_DIR)
69
+ raise ArgumentError, "No files found for path pattern \"#{path_pattern}\"" if result.empty?
74
70
 
75
- path_pattern
76
- end
77
- end
71
+ result
72
+ else
73
+ raise ArgumentError, "File \"#{path_pattern}\" doesn't exist" if !File.exist?(path_pattern)
78
74
 
79
- # @param hash [Hash<String, Array<String>>]
80
- # @return [Array<String>]
81
- def flatten_path_patterns(hash)
82
- hash.flat_map { |dir, paths| paths.map { |x| File.join(dir, x) } }
75
+ path_pattern
83
76
  end
77
+ end
84
78
 
85
- # @param dirs [Array<String>]
86
- # @return [void]
87
- def ignored(*dirs)
88
- sources = Files::Sources.new.extract("ignored", dir_names_without_slash(dirs))
79
+ # @param hash [Hash<String, Array<String>>]
80
+ # @return [Array<String>]
81
+ def flatten_path_patterns(hash)
82
+ hash.flat_map { |dir, paths| paths.map { |x| File.join(dir, x) } }
83
+ end
89
84
 
90
- puts collect_files(sources).sort
91
- end
85
+ # @param dirs [Array<String>]
86
+ # @return [void]
87
+ def ignored(*dirs)
88
+ sources = Skap::Files::Sources.new.extract("ignored", dir_names_without_slash(dirs))
92
89
 
93
- # @param dirs [Array<String>]
94
- # @return [void]
95
- def outdated(*dirs)
96
- dirs = dir_names_with_slash(dirs)
90
+ puts collect_files(sources).sort
91
+ end
97
92
 
98
- outdated_documents =
99
- Files::Versions.new.outdated_documents do |source_path|
100
- dirs.empty? || source_path.start_with?(*dirs) ? commit_sha(source_path) : nil
101
- end
93
+ # @param dirs [Array<String>]
94
+ # @return [void]
95
+ def outdated(*dirs)
96
+ dirs = dir_names_with_slash(dirs)
102
97
 
103
- outdated_documents.each do |(doc_path, outdated_sources)|
104
- puts doc_path, outdated_sources.map { |x| "* #{x}" }, ""
98
+ outdated_documents =
99
+ Skap::Files::Versions.new.outdated_documents do |source_path|
100
+ dirs.empty? || source_path.start_with?(*dirs) ? commit_sha(source_path) : nil
105
101
  end
106
- end
107
102
 
108
- # @param document_path [String]
109
- # @param sources_paths [Array<String>]
110
- # @return [void]
111
- def publish(document_path, *sources_paths)
112
- excluded_file_paths = sources_paths.select { |x| x.start_with?("-") }
113
- added_file_paths = sources_paths - excluded_file_paths
103
+ outdated_documents.each do |(doc_path, outdated_sources)|
104
+ puts doc_path, outdated_sources.map { |x| "* #{x}" }, ""
105
+ end
106
+ end
114
107
 
115
- excluded_file_paths.map! { |x| x[1..] }
108
+ # @param document_path [String]
109
+ # @param sources_paths [Array<String>]
110
+ # @return [void]
111
+ def publish(document_path, *sources_paths)
112
+ excluded_file_paths = sources_paths.select { |x| x.start_with?("-") }
113
+ added_file_paths = sources_paths - excluded_file_paths
116
114
 
117
- versions = Files::Versions.new
118
- doc = versions.find_document(document_path) || {}
115
+ excluded_file_paths.map! { |x| x[1..] }
119
116
 
120
- update_document_info(doc, added_file_paths, excluded_file_paths)
121
- versions.add_document(document_path, doc)
117
+ versions = Skap::Files::Versions.new
118
+ doc = versions.find_document(document_path) || {}
122
119
 
123
- puts "Version updated for #{document_path} in #{Files::Versions.file_name}"
124
- end
120
+ update_document_info(doc, added_file_paths, excluded_file_paths)
121
+ versions.add_document(document_path, doc)
125
122
 
126
- # @param path_patterns_as_hash [Hash<String, Hash<String, Array<String>>>]
127
- # @return [Array<String>]
128
- def trackable_files(sources_data)
129
- sources_data
130
- .extract("file-extensions")
131
- .transform_values { |v| v.join(",") }
132
- .reduce([]) { |a, (dir, ext)| a + Dir.glob("#{dir}/**/*.{#{ext}}") }
133
- end
123
+ puts "Version updated for #{document_path} in #{Skap::Files::Versions.file_name}"
124
+ end
134
125
 
135
- # @param dirs [Array<String>]
136
- # @return [void]
137
- def uncovered(*dirs)
138
- sources = Files::Sources.new.extract("indexed", dir_names_without_slash(dirs))
126
+ # @param path_patterns_as_hash [Hash<String, Hash<String, Array<String>>>]
127
+ # @return [Array<String>]
128
+ def trackable_files(sources_data)
129
+ sources_data
130
+ .extract("file-extensions")
131
+ .transform_values { |v| v.join(",") }
132
+ .reduce([]) { |a, (dir, ext)| a + Dir.glob("#{dir}/**/*.{#{ext}}") }
133
+ end
139
134
 
140
- puts (collect_files(sources) - Files::Versions.new.covered_sources.to_a).sort
141
- end
135
+ # @param dirs [Array<String>]
136
+ # @return [void]
137
+ def uncovered(*dirs)
138
+ sources = Skap::Files::Sources.new.extract("indexed", dir_names_without_slash(dirs))
142
139
 
143
- # @param dirs [Array<String>]
144
- # @return [void]
145
- def unknown(*dirs)
146
- sources_data = Files::Sources.new
147
- sources_data.select_directories!(dir_names_without_slash(dirs)) if !dirs.empty?
140
+ puts (collect_files(sources) - Skap::Files::Versions.new.covered_sources.to_a).sort
141
+ end
148
142
 
149
- all_files = trackable_files(sources_data)
150
- ignored_files = collect_files(sources_data.extract("ignored"))
151
- indexed_files = collect_files(sources_data.extract("indexed"))
143
+ # @param dirs [Array<String>]
144
+ # @return [void]
145
+ def unknown(*dirs)
146
+ sources_data = Skap::Files::Sources.new
147
+ sources_data.select_directories!(dir_names_without_slash(dirs)) if !dirs.empty?
152
148
 
153
- puts (all_files - ignored_files - indexed_files).sort
154
- end
149
+ all_files = trackable_files(sources_data)
150
+ ignored_files = collect_files(sources_data.extract("ignored"))
151
+ indexed_files = collect_files(sources_data.extract("indexed"))
155
152
 
156
- # @param doc [Hash<String, Object>]
157
- # @param added_file_paths [Array<String>]
158
- # @param excluded_file_paths [Array<String>]
159
- # @return [void]
160
- def update_document_info(doc, added_file_paths, excluded_file_paths)
161
- today = Time.now.strftime("%F")
153
+ puts (all_files - ignored_files - indexed_files).sort
154
+ end
162
155
 
163
- doc["date"] = today
164
- doc["sources"] ||= {}
156
+ # @param doc [Hash<String, Object>]
157
+ # @param added_file_paths [Array<String>]
158
+ # @param excluded_file_paths [Array<String>]
159
+ # @return [void]
160
+ def update_document_info(doc, added_file_paths, excluded_file_paths)
161
+ today = Time.now.strftime("%F")
165
162
 
166
- added_file_paths.each do |path|
167
- entry = (doc["sources"][path] ||= {})
168
- entry["date"] = today
169
- entry["sha"] = commit_sha(path)
170
- end
163
+ doc["date"] = today
164
+ doc["sources"] ||= {}
171
165
 
172
- excluded_file_paths.each { |x| doc["sources"].delete(x) }
166
+ added_file_paths.each do |path|
167
+ entry = (doc["sources"][path] ||= {})
168
+ entry["date"] = today
169
+ entry["sha"] = commit_sha(path)
173
170
  end
171
+
172
+ excluded_file_paths.each { |x| doc["sources"].delete(x) }
174
173
  end
175
174
  end
data/lib/skap/cli.rb CHANGED
@@ -13,21 +13,21 @@ require_relative "files/menu"
13
13
  require_relative "files/sources"
14
14
  require_relative "files/versions"
15
15
 
16
- module Skap
17
- module CLI
18
- # @param argv [Array<String>]
19
- # @return [void]
20
- def self.start(argv = ARGV)
21
- section, command, *rest = argv
16
+ # Dispatcher for CLI commands.
17
+ module Skap::CLI
18
+ # @param argv [Array<String>]
19
+ # @return [void]
20
+ def self.start(argv = ARGV)
21
+ section, command, *rest = argv
22
22
 
23
- case section
24
- when "works" then CLI::Works.start(command, rest)
25
- when "help", "--help", "-h", nil then CLI::Help.start
26
- when "init" then CLI::Init.start(command, rest)
27
- when "sources" then CLI::Sources.start(command, rest)
28
- else
29
- raise ArgumentError, "Unknown section: #{section}"
30
- end
23
+ case section
24
+ when "help", "--help", "-h", nil then Skap::CLI::Help.start
25
+ when "init" then Skap::CLI::Init.start(command, rest)
26
+ when "sources" then Skap::CLI::Sources.start(command, rest)
27
+ when "version", "--version", "-v" then Skap::CLI::Version.start
28
+ when "works" then Skap::CLI::Works.start(command, rest)
29
+ else
30
+ raise ArgumentError, "Unknown section: #{section}"
31
31
  end
32
32
  end
33
33
  end
@@ -38,4 +38,5 @@ end
38
38
  require_relative "cli/help"
39
39
  require_relative "cli/init"
40
40
  require_relative "cli/sources"
41
+ require_relative "cli/version"
41
42
  require_relative "cli/works"
data/lib/skap/command.rb CHANGED
@@ -1,28 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Skap
4
- module Command
5
- CURRENT_DIR = Dir.pwd.freeze
3
+ # Common class for CLI command.
4
+ module Skap::Command
5
+ CURRENT_DIR = Dir.pwd.freeze
6
6
 
7
- private
7
+ private
8
8
 
9
- # @return [void]
10
- def assert_cwd
11
- raise "Current dir isn't a repo for sources" if !File.exist?(Files::Sources.file_name)
12
- end
9
+ # @return [void]
10
+ def assert_cwd
11
+ raise "Current dir isn't a repo for sources" if !File.exist?(Skap::Files::Sources.file_name)
12
+ end
13
13
 
14
- # @param args [Array<String>]
15
- # @return [void]
16
- def assert_empty_options(args)
17
- raise ArgumentError, "Unknown options: #{args.inspect}" if !args.empty?
18
- end
14
+ # @param args [Array<String>]
15
+ # @return [void]
16
+ def assert_empty_options(args)
17
+ raise ArgumentError, "Unknown options: #{args.inspect}" if !args.empty?
18
+ end
19
19
 
20
- # @param cmd [String]
21
- # @param dir [String]
22
- # @return [String]
23
- def shell(cmd, dir: "")
24
- dir = dir == "~" ? Dir.home : File.absolute_path(dir, CURRENT_DIR)
25
- `cd #{dir} && #{cmd}`.strip
26
- end
20
+ # @param cmd [String]
21
+ # @param dir [String]
22
+ # @return [String]
23
+ def shell(cmd, dir: "")
24
+ dir = dir == "~" ? Dir.home : File.absolute_path(dir, CURRENT_DIR)
25
+ `cd #{dir} && #{cmd}`.strip
27
26
  end
28
27
  end
@@ -2,16 +2,13 @@
2
2
 
3
3
  require "forwardable"
4
4
 
5
- module Skap
6
- module Files
7
- class Menu < YAMLFile
8
- extend Forwardable
5
+ # Class for file "menu.yaml" (this file is part of Skap).
6
+ class Skap::Files::Menu < Skap::YAMLFile
7
+ extend Forwardable
9
8
 
10
- SKAP_DIR = File.expand_path("../../..", __dir__).freeze
9
+ SKAP_DIR = File.expand_path("../../..", __dir__).freeze
11
10
 
12
- self.file_name = File.join(SKAP_DIR, "menu.yaml")
11
+ self.file_name = File.join(SKAP_DIR, "menu.yaml")
13
12
 
14
- def_delegators :file, :each
15
- end
16
- end
13
+ def_delegators :file, :each
17
14
  end
@@ -1,25 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Skap
4
- module Files
5
- class Sources < YAMLFile
6
- self.file_name = "sources.yaml"
3
+ # Class for file "sources.yaml" (this file describes sources in project repository).
4
+ class Skap::Files::Sources < Skap::YAMLFile
5
+ self.file_name = "sources.yaml"
7
6
 
8
- # @param key [String]
9
- # @param dirs [Array<String>]
10
- # @return [Hash<String, Array<String>>]
11
- def extract(key, dirs = [])
12
- sources = dirs.empty? ? file : file.slice(*dirs)
13
- sources
14
- .transform_values { |v| v[key] }
15
- .reject { |_, v| v.nil? || v.empty? }
16
- end
7
+ # @param dir [String]
8
+ # @return [void]
9
+ def add_source(dir)
10
+ file[dir] = {"file-extensions" => [], "ignored" => [], "indexed" => []}
11
+ @file = file.sort_by(&:first).to_h
17
12
 
18
- # @param dirs [Array<String>]
19
- # @return [Hash<String, Hash<String, Array<String>>>]
20
- def select_directories!(dirs)
21
- @file = file.slice(*dirs)
22
- end
23
- end
13
+ update_file
14
+ end
15
+
16
+ # @param dir [String]
17
+ # @return [void]
18
+ def delete_source(dir)
19
+ file.delete(dir)
20
+ update_file
21
+ end
22
+
23
+ # @param key [String]
24
+ # @param dirs [Array<String>]
25
+ # @return [Hash<String, Array<String>>]
26
+ def extract(key, dirs = [])
27
+ sources = dirs.empty? ? file : file.slice(*dirs)
28
+ sources
29
+ .transform_values { |v| v[key] }
30
+ .reject { |_, v| v.nil? || v.empty? }
31
+ end
32
+
33
+ # @param dirs [Array<String>]
34
+ # @return [Hash<String, Hash<String, Array<String>>>]
35
+ def select_directories!(dirs)
36
+ @file = file.slice(*dirs)
24
37
  end
25
38
  end
@@ -1,48 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Skap
4
- module Files
5
- class Versions < YAMLFile
6
- self.file_name = "versions.yaml"
7
-
8
- # @param document_path [String]
9
- # @param document [Hash<String, Object>]
10
- # @return [void]
11
- def add_document(document_path, document)
12
- file[document_path] = document
13
- @file = file.sort_by(&:first).to_h
14
-
15
- File.write(self.class.file_name, Psych.dump(file, line_width: 100))
16
- end
17
-
18
- # @return [Set<String>]
19
- def covered_sources
20
- result = Set.new
21
-
22
- file.each_value { |value| result.merge(value["sources"].keys) }
23
-
24
- result
25
- end
26
-
27
- # @param document_path [String]
28
- # @return [Hash<String, Object>]
29
- def find_document(document_path)
30
- file[document_path]
31
- end
32
-
33
- # @return [Array<Array(String, Array<String>)>]
34
- def outdated_documents
35
- sources_sha = {}
36
-
37
- file.filter_map do |doc_path, hash|
38
- outdated_sources =
39
- hash["sources"].filter_map do |source_path, source_data|
40
- sha = (sources_sha[source_path] ||= yield(source_path))
41
- source_path if !sha.nil? && sha != source_data["sha"]
42
- end
43
- [doc_path, outdated_sources] if !outdated_sources.empty?
3
+ # Class for file "versions.yaml" (this file describes versions of works in project repository).
4
+ class Skap::Files::Versions < Skap::YAMLFile
5
+ self.file_name = "versions.yaml"
6
+
7
+ # @param document_path [String]
8
+ # @param document [Hash<String, Object>]
9
+ # @return [void]
10
+ def add_document(document_path, document)
11
+ file[document_path] = document
12
+ @file = file.sort_by(&:first).to_h
13
+
14
+ update_file
15
+ end
16
+
17
+ # @return [Set<String>]
18
+ def covered_sources
19
+ result = Set.new
20
+
21
+ file.each_value { |value| result.merge(value["sources"].keys) }
22
+
23
+ result
24
+ end
25
+
26
+ # @param document_path [String]
27
+ # @return [Hash<String, Object>]
28
+ def find_document(document_path)
29
+ file[document_path]
30
+ end
31
+
32
+ # @return [Array<Array(String, Array<String>)>]
33
+ def outdated_documents
34
+ sources_sha = {}
35
+
36
+ file.filter_map do |doc_path, hash|
37
+ outdated_sources =
38
+ hash["sources"].filter_map do |source_path, source_data|
39
+ sha = (sources_sha[source_path] ||= yield(source_path))
40
+ source_path if !sha.nil? && sha != source_data["sha"]
44
41
  end
45
- end
42
+ [doc_path, outdated_sources] if !outdated_sources.empty?
46
43
  end
47
44
  end
48
45
  end
@@ -1,49 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Skap
4
- module StringUtils
5
- extend self
6
-
7
- # @param paragraph [String]
8
- # @param max_width [Integer]
9
- # @return [Array<String>]
10
- def break_by_words(paragraph, max_width)
11
- words = paragraph.split
12
- parts = [[]]
13
- line_width = 0
14
-
15
- while !words.empty?
16
- word = words.shift
17
- new_line_width = (line_width == 0 ? line_width : line_width + 1) + word.size
18
- line_width = add_word(word, parts, new_line_width, max_width)
19
- end
3
+ # Manipulations with strings.
4
+ module Skap::StringUtils
5
+ extend self
6
+
7
+ # @param paragraph [String]
8
+ # @param max_width [Integer]
9
+ # @return [Array<String>]
10
+ def break_by_words(paragraph, max_width)
11
+ words = paragraph.split
12
+ parts = [[]]
13
+ line_width = 0
14
+
15
+ while !words.empty?
16
+ word = words.shift
17
+ new_line_width = (line_width == 0 ? line_width : line_width + 1) + word.size
18
+ line_width = add_word(word, parts, new_line_width, max_width)
19
+ end
20
20
 
21
- parts.pop if parts.last.empty?
21
+ parts.pop if parts.last.empty?
22
22
 
23
- parts.map { |line| line.join(" ") }
24
- end
23
+ parts.map { |line| line.join(" ") }
24
+ end
25
+
26
+ private
27
+
28
+ # @param word [String]
29
+ # @param parts [Array<String>]
30
+ # @param new_line_width [Integer]
31
+ # @param max_width [Integer]
32
+ # @return [Integer] Current line width
33
+ def add_word(word, parts, new_line_width, max_width) # rubocop:disable Metrics/MethodLength
34
+ if new_line_width <= max_width
35
+ parts.last << word
25
36
 
26
- private
27
-
28
- # @param word [String]
29
- # @param parts [Array<String>]
30
- # @param new_line_width [Integer]
31
- # @param max_width [Integer]
32
- # @return [Integer] Current line width
33
- def add_word(word, parts, new_line_width, max_width) # rubocop:disable Metrics/MethodLength
34
- if new_line_width <= max_width
35
- parts.last << word
36
-
37
- if new_line_width == max_width
38
- parts << []
39
- 0
40
- else
41
- new_line_width
42
- end
37
+ if new_line_width == max_width
38
+ parts << []
39
+ 0
43
40
  else
44
- parts << [word]
45
- word.size
41
+ new_line_width
46
42
  end
43
+ else
44
+ parts << [word]
45
+ word.size
47
46
  end
48
47
  end
49
48
  end
data/lib/skap/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Skap
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.3"
5
5
  end
@@ -1,24 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Skap
4
- class YAMLFile
5
- class << self
6
- attr_accessor :file_name
3
+ # Common class for reading & updating YAML files.
4
+ class Skap::YAMLFile
5
+ class << self
6
+ attr_accessor :file_name
7
7
 
8
- private :file_name=
9
- end
8
+ private :file_name=
9
+ end
10
+
11
+ def initialize
12
+ @file = load_file
13
+ end
10
14
 
11
- def initialize
12
- @file = load_file
13
- end
15
+ private
14
16
 
15
- private
17
+ attr_reader :file
16
18
 
17
- attr_reader :file
19
+ # @return [Hash<String, Object>]
20
+ def load_file
21
+ Psych.load_file(self.class.file_name, symbolize_names: false) || {}
22
+ end
18
23
 
19
- # @return [Hash<String, Object>]
20
- def load_file
21
- Psych.load_file(self.class.file_name, symbolize_names: false) || {}
22
- end
24
+ # @return [void]
25
+ def update_file
26
+ File.write(self.class.file_name, Psych.dump(file, line_width: 100))
23
27
  end
24
28
  end
data/lib/skap.rb CHANGED
@@ -1,4 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Skap, document management system.
4
+ module Skap
5
+ # Class wrappers for files with settings.
6
+ module Files
7
+ end
8
+ end
9
+
3
10
  require_relative "skap/cli"
4
11
  require_relative "skap/version"
data/menu.yaml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- - cmd: help
2
+ - cmd: ["help", "--help", "-h"]
3
3
  text: "Show help message about supported commands."
4
4
  - cmd: ["init", "init DIRECTORY_PATH"]
5
5
  text: "Create configuration files in current directory or in DIRECTORY_PATH."
@@ -14,6 +14,8 @@
14
14
  Update git submodule from upstream in DIRECTORY or in all git submodules if DIRECTORY
15
15
  is not specified. You may pass one or more directory paths (DIRECTORY ...) to update
16
16
  their contents.
17
+ - cmd: ["version", "--version", "-v"]
18
+ text: "Show program version"
17
19
  - cmd: works
18
20
  children:
19
21
  - cmd: ["covered", "covered DIRECTORY ..."]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Nochevnov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-28 00:00:00.000000000 Z
11
+ date: 2024-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
@@ -94,6 +94,7 @@ files:
94
94
  - lib/skap/cli/help.rb
95
95
  - lib/skap/cli/init.rb
96
96
  - lib/skap/cli/sources.rb
97
+ - lib/skap/cli/version.rb
97
98
  - lib/skap/cli/works.rb
98
99
  - lib/skap/command.rb
99
100
  - lib/skap/files/menu.rb
@@ -125,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  - !ruby/object:Gem::Version
126
127
  version: '0'
127
128
  requirements: []
128
- rubygems_version: 3.5.19
129
+ rubygems_version: 3.5.23
129
130
  signing_key:
130
131
  specification_version: 4
131
132
  summary: ''