smp_tool-cli 0.1.1 → 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: fd85230de1a516aa00d00cfc1cb4b6cc974d31911f5ffc9e9f960308d9ab3305
4
- data.tar.gz: 5564aaf53a4f2b3404a0ab017b5310e04b71e0863d6e2a6ced8bc4a8df83d074
3
+ metadata.gz: c83c658d44b09650948b0d0b94e34250ac9a41b374651ed34ed64675678f122b
4
+ data.tar.gz: a4052f1740f90749c0dd998850eef0c7d0e6bfd7c54fbb79d2f2dfad03ff9a05
5
5
  SHA512:
6
- metadata.gz: 2d121db1b7ece3b790b9d161b61edb4f2cb1cb70ab1abdfcb729da0274a5f9d26d129d2dde277f8cd98354217850405b19d0b4f0f5dadc33f0383a0f49646cf9
7
- data.tar.gz: be1b984472598136b0da421e7bcb00007335adf5d9930416042b186d04bed846079ac7f5f90bf803d145e3780e9161d67cdcd5568df8d2787528595121a9bc5c
6
+ metadata.gz: 780ab66ca40a0abebd11a47e6f1415429593776d4545c723b1ee94b72928a7e04f82d6a024d70835d12fc96bd7bca6c0824842b6b0f2eec54a5bbd8504d86790
7
+ data.tar.gz: 5abbc23d7cbae441f7760a1d030fcc05ebd783c7d4c70bf7af037b0938f4e9a9471654f2357d91298ea890e2783f803c84b6b386a7eb9033e4e0798a5a1d8409
data/CHANGELOG.md CHANGED
@@ -1,7 +1,12 @@
1
+ ## [0.2.0] - 2024-03-17
2
+
3
+ * `--raw` option for the extract command
4
+ * more advanced `delete` command
5
+
1
6
  ## [0.1.1] - 2024-03-15
2
7
 
3
- - Few changes in the UI
8
+ * Few changes in the UI
4
9
 
5
10
  ## [0.1.0] - 2024-03-14
6
11
 
7
- - 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,7 +17,7 @@ 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,
@@ -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
@@ -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
@@ -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
@@ -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.1"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  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.1
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-15 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
@@ -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