diskman 1.0.5 → 1.0.9

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: fc55f72e8adacb9143ad05cf5edc11c2db9d8be185569bb9263735efcbe54700
4
- data.tar.gz: 28a1cfa67910767440b3f6293192ddd05be1194e3b9a7246ed304b3bdb33df3c
3
+ metadata.gz: 356141ac045d586f1d8dec632762474496de583c2cd1f9199b392ad273baf123
4
+ data.tar.gz: '09057fecdaa82c8fddac9a7ed21c2d172f0cc1e342331d226967f908e0330906'
5
5
  SHA512:
6
- metadata.gz: b07d213e836deffc0998b14e57e68a4b41f509cf3ba7e7d60d488c6ee8a9f376c7032c90e34a1fb603bee553aaa81902145dfe2a83ca79d1bd976627e269c18d
7
- data.tar.gz: 0f68a40ed3db1504f00b05765a646fd57e1e8686fb37e6d1b6e6a7af93303bbd2b4018dffafa9b9ab27a434be3a30b8d4ef5b96cee8f988a768fbddbd51f2729
6
+ metadata.gz: 1c5c298f9849ef5e25d952b8bc782749c2b98075ef9289f2379f708932c4041bb301cb22dcbe0fa90337fae41103af8b8f9c0079ba7a414935222094b621ffc7
7
+ data.tar.gz: e840f6c4bb49c3a6f8559494986c082515d3ff8f8c9b705d9d4f9a32bd9794308e21d6044296a03c5dd8305f34a626ce10d2aeb7cfb488491c1931bc9da9d4cb
data/bin/diskman CHANGED
@@ -1,8 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
  require_relative '../lib/diskman'
3
+ require 'docopt'
4
+
3
5
  include Diskman
4
6
 
5
- require 'docopt'
7
+ Params = Struct.new(
8
+ :version,
9
+ :list,
10
+ :write,
11
+ :fdisk,
12
+ :mkfs,
13
+ :file,
14
+ keyword_init: true,
15
+ )
6
16
 
7
17
  class Main
8
18
  def initialize(opts)
@@ -14,30 +24,21 @@ class Main
14
24
  end
15
25
 
16
26
  def params
17
- @params ||= OpenStruct.new({
27
+ @params ||= Params.new(
18
28
  version: @opts['--version'],
19
- help: @opts['--help'],
20
29
  list: @opts['--list'],
21
30
  write: @opts['write'],
22
31
  fdisk: @opts['fdisk'],
23
32
  mkfs: @opts['mkfs'],
24
33
  file: @opts['<file>'],
25
- })
26
- end
27
-
28
- def exit_usage
29
- puts DOCS
30
- exit 0
31
- end
32
-
33
- def exit_version
34
- puts Diskman::VERSION
35
- exit 0
34
+ )
36
35
  end
37
36
 
38
37
  def run
39
- exit_version if params.version
40
- exit_usage if params.help
38
+ if params.version
39
+ puts VERSION
40
+ exit
41
+ end
41
42
 
42
43
  if params.mkfs
43
44
  Command::Mkfs.new.run(list: params.list)
@@ -46,25 +47,25 @@ class Main
46
47
  elsif params.fdisk
47
48
  Command::Fdisk.new.run
48
49
  end
49
- rescue Interrupt => e
50
+ rescue Interrupt # rubocop:disable Lint/SuppressedException
50
51
  end
51
52
  end
52
53
 
53
- docs = <<~EOF
54
- #{'Usage:'.bold}
54
+ usage = <<~EOF
55
+ Usage:
55
56
  #{File.basename($0)} write <file>
56
57
  #{File.basename($0)} fdisk
57
- #{File.basename($0)} mkfs [ --list ]
58
+ #{File.basename($0)} mkfs [--list]
58
59
  #{File.basename($0)} ( --version | --help )
59
60
 
60
- #{'Options:'.bold}
61
- -v, --version Show version
62
- -h, --help Show this help
61
+ Options:
62
+ -v, --version Show version
63
+ -h, --help Show this help
63
64
  EOF
64
65
 
65
66
  begin
66
- Main.run(Docopt::docopt(docs, version: VERSION))
67
- rescue Docopt::Exit => e
68
- puts e.message
69
- exit 1
67
+ Main.run(Docopt.docopt(usage))
68
+ rescue Docopt::Exit
69
+ puts usage
70
+ exit 2
70
71
  end
@@ -30,7 +30,7 @@ module Diskman
30
30
  puts
31
31
 
32
32
  @items.each_with_index do |device, i|
33
- puts "%6d. %s" % [i + 1, device]
33
+ puts '%6d. %s' % [i + 1, device]
34
34
  end
35
35
 
36
36
  puts
@@ -3,7 +3,7 @@ module Command
3
3
  def run
4
4
  root_device = RootDevice.choose
5
5
  cmd = root_device.get_fdisk_command
6
- System.exec! cmd, safe: false
6
+ System.exec!(cmd, safe: false)
7
7
  end
8
8
  end
9
9
  end
@@ -22,7 +22,7 @@ module Command
22
22
  puts "Device: #{device.to_s.yellow}"
23
23
  puts "Command: #{cmd.yellow}"
24
24
 
25
- System.exec! cmd
25
+ System.exec!(cmd)
26
26
  end
27
27
  end
28
28
  end
@@ -1,7 +1,7 @@
1
1
  module Command
2
2
  class Write
3
3
  def run(file:)
4
- if !File.exists?(file)
4
+ if !File.exist?(file)
5
5
  puts ('Unable to read ' + file).red
6
6
  raise Interrupt
7
7
  end
@@ -10,13 +10,13 @@ module Command
10
10
  device = device.choose_with_partitions
11
11
 
12
12
  size = File.size(file)
13
- cmd = device.get_write_command(file, size)
13
+ cmd = device.get_write_command(file)
14
14
 
15
15
  puts "File: #{file.yellow} (#{System.bytes2human(size)})"
16
16
  puts "Device: #{device.to_s.yellow}"
17
17
  puts "Command: #{cmd.yellow}"
18
18
 
19
- System.exec! cmd
19
+ System.exec!(cmd)
20
20
  end
21
21
  end
22
22
  end
@@ -1,7 +1,7 @@
1
1
  module Diskman
2
2
  # Confirms whether the user wants to do something destructive.
3
3
  class Confirmer
4
- YES = 'YES'
4
+ YES = 'yes'
5
5
 
6
6
  def self.check!
7
7
  new.check!
@@ -9,7 +9,7 @@ module Diskman
9
9
 
10
10
  def check!
11
11
  puts
12
- puts 'Are you sure? Type "%s" if so.' % YES
12
+ puts 'Are you sure? Type "%s"' % YES
13
13
  puts
14
14
 
15
15
  print '> '
@@ -16,7 +16,7 @@ module Diskman
16
16
  'sudo mkfs.%s %s' % [fs, @path]
17
17
  end
18
18
 
19
- def get_write_command(path, bytes)
19
+ def get_write_command(path)
20
20
  dd = 'sudo dd if="%s" of="%s" bs=%dK status=progress'
21
21
  dd % [path, @path, 4096]
22
22
  end
@@ -27,8 +27,8 @@ module Diskman
27
27
 
28
28
  private
29
29
 
30
- def <=>(o)
31
- @path <=> o.path
30
+ def <=>(other)
31
+ @path <=> other.path
32
32
  end
33
33
  end
34
34
  end
@@ -35,7 +35,7 @@ module Diskman
35
35
  private
36
36
 
37
37
  def get_with_partitions
38
- Dir[@path + '*'].sort.map do |file|
38
+ Dir[@path + '*'].map do |file|
39
39
  file =~ %r[/dev/(.*)] && Device.new($1)
40
40
  end.sort
41
41
  end
@@ -45,7 +45,7 @@ module Diskman
45
45
  end
46
46
 
47
47
  def get_prop(name)
48
- file = "/sys/class/block/%s/%s" % [@name, name]
48
+ file = '/sys/class/block/%s/%s' % [@name, name]
49
49
  File.read(file).strip.gsub(/\s+/, ' ')
50
50
  end
51
51
 
@@ -15,7 +15,7 @@ module Diskman
15
15
  Confirmer.check! if safe
16
16
  prepare_sudo_session! if sudo
17
17
  puts
18
- exec cmd
18
+ exec(cmd)
19
19
  end
20
20
 
21
21
  # Convert bytes into a human-friendly representation.
@@ -26,7 +26,7 @@ module Diskman
26
26
  # advertised.
27
27
  k = 1000
28
28
 
29
- suffixes = ['T', 'G', 'M', 'K', 'B']
29
+ suffixes = %w[T G M K B]
30
30
 
31
31
  suffixes.each_with_index do |suffix, i|
32
32
  threshold = k ** (suffixes.length - i - 1)
@@ -1,3 +1,3 @@
1
1
  module Diskman
2
- VERSION = "1.0.5"
2
+ VERSION = '1.0.9'
3
3
  end
data/lib/diskman.rb CHANGED
@@ -5,7 +5,7 @@ require 'ostruct'
5
5
 
6
6
  module Diskman
7
7
  def self.root_dir
8
- File.expand_path('../..', __FILE__)
8
+ File.expand_path('..', __dir__)
9
9
  end
10
10
  end
11
11
 
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diskman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - crdx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: require_all
14
+ name: colorize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: 0.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: 0.8.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: colorize
28
+ name: docopt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.1
33
+ version: 0.6.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.8.1
40
+ version: 0.6.1
41
41
  - !ruby/object:Gem::Dependency
42
- name: docopt
42
+ name: require_all
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.6.1
47
+ version: '3.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.6.1
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: simplecov
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.21.0
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.21.0
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,19 +81,19 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.8'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rake
84
+ name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '13.0'
89
+ version: 0.21.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '13.0'
96
+ version: 0.21.0
97
97
  description:
98
98
  email:
99
99
  executables:
@@ -116,7 +116,8 @@ files:
116
116
  homepage: https://github.com/crdx/diskman
117
117
  licenses:
118
118
  - MIT
119
- metadata: {}
119
+ metadata:
120
+ rubygems_mfa_required: 'true'
120
121
  post_install_message:
121
122
  rdoc_options: []
122
123
  require_paths:
@@ -125,14 +126,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
126
  requirements:
126
127
  - - ">="
127
128
  - !ruby/object:Gem::Version
128
- version: '0'
129
+ version: '3.0'
129
130
  required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  requirements:
131
132
  - - ">="
132
133
  - !ruby/object:Gem::Version
133
134
  version: '0'
134
135
  requirements: []
135
- rubygems_version: 3.2.21
136
+ rubygems_version: 3.2.29
136
137
  signing_key:
137
138
  specification_version: 4
138
139
  summary: Interactive command line interface for safely managing disks