smp_tool-cli 0.1.0 → 0.2.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: da03ac32fe8ebcf2d0f32f19d49f37b48b7404289bc91cf006e45c4dddc353a1
4
- data.tar.gz: 78a43fdd3e6f1f533681e362786ad8059bb07a39703d2e0d6d4dda3f5ffe29da
3
+ metadata.gz: c83c658d44b09650948b0d0b94e34250ac9a41b374651ed34ed64675678f122b
4
+ data.tar.gz: a4052f1740f90749c0dd998850eef0c7d0e6bfd7c54fbb79d2f2dfad03ff9a05
5
5
  SHA512:
6
- metadata.gz: a060a0c98f3bef66ef1984f30f0e6098e0219789197009acef2ca157cfa013ee08112df4ef0ea2a0bc6af2fc8b19a690114a7371ae53057c1dd97ad5f7e50c53
7
- data.tar.gz: 358a6164fb66b79767900a0f8506304636ce1d67c2201ad2059e39aebe52388dd3dea7fabd34d9e0378c2ab330283a0744b9f6beabd29dd2336c30c5fe61af50
6
+ metadata.gz: 780ab66ca40a0abebd11a47e6f1415429593776d4545c723b1ee94b72928a7e04f82d6a024d70835d12fc96bd7bca6c0824842b6b0f2eec54a5bbd8504d86790
7
+ data.tar.gz: 5abbc23d7cbae441f7760a1d030fcc05ebd783c7d4c70bf7af037b0938f4e9a9471654f2357d91298ea890e2783f803c84b6b386a7eb9033e4e0798a5a1d8409
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.2.0] - 2024-03-17
2
+
3
+ * `--raw` option for the extract command
4
+ * more advanced `delete` command
5
+
6
+ ## [0.1.1] - 2024-03-15
7
+
8
+ * Few changes in the UI
9
+
1
10
  ## [0.1.0] - 2024-03-14
2
11
 
3
- - Initial release
12
+ * Initial release
@@ -4,20 +4,28 @@ module SMPTool
4
4
  module CLI
5
5
  module Commands
6
6
  #
7
- # Delete a file from the volume.
7
+ # Delete file(s) from the volume.
8
8
  #
9
9
  class Delete < VolumeOperation
10
- desc "Delete a file from the volume"
10
+ desc "Delete files from the volume"
11
11
 
12
- option :filename,
12
+ option :f_list,
13
+ type: :array,
13
14
  required: true,
14
- desc: "File to delete",
15
+ desc: "File(s) to delete",
15
16
  aliases: ["-f"]
16
17
 
17
- def call(input:, filename:, **options)
18
+ option :squeeze,
19
+ type: :boolean,
20
+ required: false,
21
+ default: false,
22
+ desc: "When done, perform the `squeeze` operation",
23
+ aliases: ["-s"]
24
+
25
+ def call(input:, f_list:, **options)
18
26
  Executor::Deleter.new(
19
27
  input: input,
20
- filename: filename,
28
+ f_list: f_list,
21
29
  logger: _logger(options[:verbosity]),
22
30
  **options
23
31
  ).call
@@ -21,7 +21,24 @@ module SMPTool
21
21
  desc: "File(s) to extract",
22
22
  aliases: ["-f"]
23
23
 
24
+ option :raw,
25
+ type: :boolean,
26
+ default: false,
27
+ required: false,
28
+ desc: "Extract as raw data",
29
+ aliases: ["-r"]
30
+
24
31
  def call(input:, f_list:, **options)
32
+ if options[:raw]
33
+ _extract_raw(input: input, f_list: f_list, **options)
34
+ else
35
+ _extract_txt(input: input, f_list: f_list, **options)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def _extract_txt(input:, f_list:, **options)
25
42
  Executor::ExtracterTxt.new(
26
43
  input: input,
27
44
  f_list: f_list,
@@ -29,6 +46,15 @@ module SMPTool
29
46
  **options
30
47
  ).call
31
48
  end
49
+
50
+ def _extract_raw(input:, f_list:, **options)
51
+ Executor::ExtracterRaw.new(
52
+ input: input,
53
+ f_list: f_list,
54
+ logger: _logger(options[:verbosity]),
55
+ **options
56
+ ).call
57
+ end
32
58
  end
33
59
  end
34
60
  end
@@ -15,13 +15,38 @@ module SMPTool
15
15
  desc: "Output directory",
16
16
  aliases: ["-d"]
17
17
 
18
+ option :raw,
19
+ type: :boolean,
20
+ default: false,
21
+ required: false,
22
+ desc: "Extract as raw data",
23
+ aliases: ["-r"]
24
+
18
25
  def call(input:, **options)
26
+ if options[:raw]
27
+ _extract_raw(input: input, **options)
28
+ else
29
+ _extract_txt(input: input, **options)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def _extract_txt(input:, **options)
19
36
  Executor::ExtracterTxtAll.new(
20
37
  input: input,
21
38
  logger: _logger(options[:verbosity]),
22
39
  **options
23
40
  ).call
24
41
  end
42
+
43
+ def _extract_raw(input:, **options)
44
+ Executor::ExtracterRawAll.new(
45
+ input: input,
46
+ logger: _logger(options[:verbosity]),
47
+ **options
48
+ ).call
49
+ end
25
50
  end
26
51
  end
27
52
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SMPTool
4
+ module CLI
5
+ module Commands
6
+ #
7
+ # Command to list files.
8
+ #
9
+ class ListFiles < InputCommand
10
+ desc "List all files on the volume"
11
+
12
+ def call(input:, **options)
13
+ Executor::FileListInformer.new(
14
+ input: input,
15
+ logger: _logger(options[:verbosity]),
16
+ **options
17
+ ).call
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -17,13 +17,13 @@ module SMPTool
17
17
 
18
18
  option :basic,
19
19
  required: true,
20
- desc: "Target Basic version { 1 | 2 }",
20
+ desc: "Target BASIC version { 1 | 2 }",
21
21
  aliases: ["-b"]
22
22
 
23
23
  option :n_clusters,
24
24
  default: DEF_N_CLUSTERS,
25
25
  required: false,
26
- desc: "Number of clusters allocated to the volume",
26
+ desc: "Number of 512-byte clusters allocated to the volume (4..127)",
27
27
  aliases: ["-c"]
28
28
 
29
29
  option :n_dir_segs,
@@ -47,8 +47,8 @@ module SMPTool
47
47
  example [
48
48
  "-b 1 # Create a BASIC v.1.0 volume with the default parameters, " \
49
49
  "save result to the `smp0.bin` file (default path)",
50
- "-b 2 -o /dir/smp.bin # Create a BASIC v.1.0 volume with the default parameters, " \
51
- "save result to the `/dir/smp.bin` file (custom path)",
50
+ "-b 2 -o dir/smp.bin # Create a BASIC v.1.0 volume with the default parameters, " \
51
+ "save result to the `dir/smp.bin` file (custom path)",
52
52
  "-b 2 -l auto # Create a BASIC v.2.0 volume with the auto-loader",
53
53
  "-b 1 -c 127 -d 2 # Create the largest possible BASIC v.1.0 volume",
54
54
  "-b 1 -s 1 # Create a BASIC v.1.0 volume with the 'trimmed' directory"
@@ -18,6 +18,7 @@ module SMPTool
18
18
  register "rename", Rename, aliases: ["r"]
19
19
  register "resize", Resize, aliases: ["z"]
20
20
  register "squeeze", Squeeze, aliases: ["s"]
21
+ register "list", ListFiles, aliases: ["l"]
21
22
 
22
23
  register "version", Version, aliases: ["-v", "--version"]
23
24
  end
@@ -4,9 +4,17 @@ module SMPTool
4
4
  module CLI
5
5
  module Executor
6
6
  class Deleter < VolReadWriteOperator
7
+ include SqueezeMixin
8
+
7
9
  def call
8
- fn = @volume.f_delete(@options[:filename])
9
- @logger.es_info "File '#{fn}' was deleted from the volume"
10
+ @options[:f_list].each do |file|
11
+ fn = @volume.f_delete(file)
12
+ @logger.info "File '#{fn}' was deleted from the volume"
13
+ end
14
+
15
+ @logger.es_info "#{@options[:f_list].length} files were deleted from the volume"
16
+
17
+ _squeeze if @options[:squeeze]
10
18
 
11
19
  super
12
20
  end
@@ -23,7 +23,7 @@ module SMPTool
23
23
  @logger.info "File '#{path}' created"
24
24
  end
25
25
 
26
- @logger.es_info "#{f_arr.length} files extracted"
26
+ @logger.es_info "#{f_arr.length} files were extracted to the directory: '#{@options[:dir]}'"
27
27
  end
28
28
 
29
29
  # Remove trailing spaces from the base filename and ext.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SMPTool
4
+ module CLI
5
+ module Executor
6
+ class ExtracterRaw < ExtracterRawBase
7
+ private
8
+
9
+ def _extract_files
10
+ @options[:f_list].map do |fn|
11
+ @volume.f_extract_raw(fn)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SMPTool
4
+ module CLI
5
+ module Executor
6
+ class ExtracterRawAll < ExtracterRawBase
7
+ private
8
+
9
+ def _extract_files
10
+ @volume.f_extract_raw_all
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SMPTool
4
+ module CLI
5
+ module Executor
6
+ class ExtracterRawBase < ExtracterBase
7
+ private
8
+
9
+ def _write_file(path, file_obj)
10
+ dry_files = Dry::Files.new
11
+ dry_files.write(path, file_obj.data)
12
+ end
13
+
14
+ def _filter_filename(filename)
15
+ "#{super}.bin"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -3,7 +3,7 @@
3
3
  module SMPTool
4
4
  module CLI
5
5
  module Executor
6
- class ExtracterTxt < ExtracterBase
6
+ class ExtracterTxt < ExtracterTxtBase
7
7
  private
8
8
 
9
9
  def _extract_files
@@ -11,11 +11,6 @@ module SMPTool
11
11
  @volume.f_extract_txt(fn)
12
12
  end
13
13
  end
14
-
15
- def _write_file(path, file_obj)
16
- dry_files = Dry::Files.new
17
- dry_files.write(path, file_obj.data.join("\n"))
18
- end
19
14
  end
20
15
  end
21
16
  end
@@ -3,17 +3,12 @@
3
3
  module SMPTool
4
4
  module CLI
5
5
  module Executor
6
- class ExtracterTxtAll < ExtracterBase
6
+ class ExtracterTxtAll < ExtracterTxtBase
7
7
  private
8
8
 
9
9
  def _extract_files
10
10
  @volume.f_extract_txt_all
11
11
  end
12
-
13
- def _write_file(path, file_obj)
14
- dry_files = Dry::Files.new
15
- dry_files.write(path, file_obj.data.join("\n"))
16
- end
17
12
  end
18
13
  end
19
14
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SMPTool
4
+ module CLI
5
+ module Executor
6
+ class ExtracterTxtBase < ExtracterBase
7
+ private
8
+
9
+ def _write_file(path, file_obj)
10
+ dry_files = Dry::Files.new
11
+ dry_files.write(path, file_obj.data.join("\n"))
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SMPTool
4
+ module CLI
5
+ module Executor
6
+ #
7
+ # Lists files on the volume.
8
+ #
9
+ class FileListInformer < VolReadOperator
10
+ def call
11
+ snapshot = @volume.snapshot
12
+
13
+ _list_files(snapshot[:volume_data])
14
+
15
+ super
16
+ end
17
+
18
+ private
19
+
20
+ def _list_files(vol_data)
21
+ vol_data.reject { |e| e[:status] == "empty" }
22
+ .each { |e| puts e[:filename] }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -7,7 +7,7 @@ module SMPTool
7
7
  # Prints info about the volume.
8
8
  #
9
9
  class Informer < VolReadOperator
10
- VOL_PAR_L = 24
10
+ VOL_PAR_L = 32
11
11
 
12
12
  F_NUM_L = 5
13
13
  F_STATUS_L = 10
@@ -26,6 +26,8 @@ module SMPTool
26
26
  super
27
27
  end
28
28
 
29
+ private
30
+
29
31
  def _choose_basic(extra_word)
30
32
  case extra_word
31
33
  when SMPTool::Basic10::ENTRY_EXTRA_WORD
@@ -44,8 +46,8 @@ module SMPTool
44
46
  def _print_vol_params(vol_params)
45
47
  puts "N. clusters allocated:".ljust(VOL_PAR_L) << vol_params[:n_clusters_allocated].to_s
46
48
  puts "N. dir. segments:".ljust(VOL_PAR_L) << vol_params[:n_dir_segs].to_s
47
- puts "Dir. seg. size:".ljust(VOL_PAR_L) << vol_params[:n_clusters_per_dir_seg].to_s
48
- puts "Directory capacity:".ljust(VOL_PAR_L) << vol_params[:n_max_entries].to_s
49
+ puts "Dir. seg. size, clusters:".ljust(VOL_PAR_L) << vol_params[:n_clusters_per_dir_seg].to_s
50
+ puts "Directory capacity, files:".ljust(VOL_PAR_L) << vol_params[:n_max_entries].to_s
49
51
  puts "Volume type:".ljust(VOL_PAR_L) << _choose_basic(vol_params[:extra_word])
50
52
  end
51
53
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SMPTool
4
+ module CLI
5
+ module Executor
6
+ module SqueezeMixin
7
+ private
8
+
9
+ def _squeeze
10
+ n_free_clusters = @volume.squeeze
11
+ @logger.es_info "#{n_free_clusters} clusters were joined into one section at the end of the volume"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -4,9 +4,10 @@ module SMPTool
4
4
  module CLI
5
5
  module Executor
6
6
  class Squeezer < VolReadWriteOperator
7
+ include SqueezeMixin
8
+
7
9
  def call
8
- n_free_clusters = @volume.squeeze
9
- @logger.es_info "#{n_free_clusters} clusters were joined into one section at the end of the volume"
10
+ _squeeze
10
11
 
11
12
  super
12
13
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SMPTool
4
4
  module CLI
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
data/smp_tool-cli.gemspec CHANGED
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "dry-cli", "~> 1.0", ">= 1.0.0"
36
36
  spec.add_dependency "dry-files", "~> 1.1", ">= 1.1.0"
37
37
  spec.add_dependency "smp_tool", "~> 0.1", ">= 0.1.0"
38
- spec.add_dependency "zeitwerk", "~> 2.6", ">= 2.6.12"
38
+ spec.add_dependency "zeitwerk", "~> 2.6", ">= 2.6.13"
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smp_tool-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 8bit-m8
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-14 00:00:00.000000000 Z
11
+ date: 2024-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -79,7 +79,7 @@ dependencies:
79
79
  version: '2.6'
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 2.6.12
82
+ version: 2.6.13
83
83
  type: :runtime
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
@@ -89,7 +89,7 @@ dependencies:
89
89
  version: '2.6'
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: 2.6.12
92
+ version: 2.6.13
93
93
  description:
94
94
  email:
95
95
  - you@example.com
@@ -114,6 +114,7 @@ files:
114
114
  - lib/smp_tool/cli/commands/extract_all.rb
115
115
  - lib/smp_tool/cli/commands/info.rb
116
116
  - lib/smp_tool/cli/commands/input_command.rb
117
+ - lib/smp_tool/cli/commands/list_files.rb
117
118
  - lib/smp_tool/cli/commands/new.rb
118
119
  - lib/smp_tool/cli/commands/push.rb
119
120
  - lib/smp_tool/cli/commands/rename.rb
@@ -127,13 +128,19 @@ files:
127
128
  - lib/smp_tool/cli/executor/creator.rb
128
129
  - lib/smp_tool/cli/executor/deleter.rb
129
130
  - lib/smp_tool/cli/executor/extracter_base.rb
131
+ - lib/smp_tool/cli/executor/extracter_raw.rb
132
+ - lib/smp_tool/cli/executor/extracter_raw_all.rb
133
+ - lib/smp_tool/cli/executor/extracter_raw_base.rb
130
134
  - lib/smp_tool/cli/executor/extracter_txt.rb
131
135
  - lib/smp_tool/cli/executor/extracter_txt_all.rb
136
+ - lib/smp_tool/cli/executor/extracter_txt_base.rb
137
+ - lib/smp_tool/cli/executor/file_list_informer.rb
132
138
  - lib/smp_tool/cli/executor/informer.rb
133
139
  - lib/smp_tool/cli/executor/operator.rb
134
140
  - lib/smp_tool/cli/executor/pusher.rb
135
141
  - lib/smp_tool/cli/executor/renamer.rb
136
142
  - lib/smp_tool/cli/executor/resizer.rb
143
+ - lib/smp_tool/cli/executor/squeeze_mixin.rb
137
144
  - lib/smp_tool/cli/executor/squeezer.rb
138
145
  - lib/smp_tool/cli/executor/vol_read_operator.rb
139
146
  - lib/smp_tool/cli/executor/vol_read_write_operator.rb