namespacer-rb 0.1.3 → 0.1.5

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: a72519123e573f5919a27d3bf9f67d8058518b99d1132a60b98ac3399b8786a3
4
- data.tar.gz: 1de535bf8f1731015d09305483673012c214d8aff07d1df2e350117ec9437b92
3
+ metadata.gz: 3e895d7e611b2619be7e4e0683066adb1776c186ddd8ea9d95e192a355e0f9ba
4
+ data.tar.gz: e5f6405e2695170de3bc656f660b69f537d63c31d5ce2fca6ec1d64dd6796008
5
5
  SHA512:
6
- metadata.gz: 64be7577c8da68f66f5dd9d709abad8150e2260f3ac68b7a74b40b117605f396c7437b2498f5d2218e5ecc5ef87967a9eddb31aeeb57bf5282f36951716faca4
7
- data.tar.gz: 758fd04be5835101752fdb695962e153f7e55ecbe3a3e34a253a6e905c453f2ff00986ecd6b3ccb6dc005bdb36a7c1dbaa3d84e9e9159146dbb0ea40a9388679
6
+ metadata.gz: 3edf5bc7256392f0ecc35d50d3e1a491c1bb368f821062bc5466329c7c5568f3da746d80f356d7943c3c53b45b88a8a31908ad51dad1e14b0c784e20a2478bff
7
+ data.tar.gz: deda785427a83e1eb9a2b66e3a91ec262c463f4e0a50b43abdfb068dd9197228c5b1d1cdf5ccb2d66b3fe4ce11634c174048800217820d121fbf5a30dc2ff02b
data/exe/namespacer CHANGED
@@ -8,13 +8,13 @@ require 'tty-command'
8
8
  module Rubyists
9
9
  # Namespace for the namespacer CLI
10
10
  module Namespacer
11
- CliOptions = Struct.new(:recursive, :verbose, :in_place)
11
+ CliOptions = Struct.new(:recursive, :verbose, :in_place, :fail_rubocop_silently)
12
12
  def self.cli_options
13
13
  @cli_options ||= CliOptions.new(verbose: false, recursive: false, in_place: false)
14
14
  end
15
15
 
16
16
  def self.cmd
17
- @cmd = TTY::Command.new
17
+ @cmd = TTY::Command.new printer: :null
18
18
  end
19
19
  end
20
20
  end
@@ -28,6 +28,15 @@ parser = OptionParser.new do |opts|
28
28
 
29
29
  opts.on('-i', '--in-place', 'Modify files in-place') { |_| options.in_place = true }
30
30
 
31
+ opts.on('-f', '--fail-rubocop-silently', 'Write files even if they are not rubocop-friendly') do |_|
32
+ options.fail_rubocop_silently = true
33
+ end
34
+
35
+ opts.on('-V', '--version', 'Print version') do
36
+ puts "namespacer #{Rubyists::Namespacer::VERSION}"
37
+ exit
38
+ end
39
+
31
40
  opts.on('-v', '--verbose', 'Verbose output') do
32
41
  options.verbose = true
33
42
  end
@@ -69,21 +78,39 @@ def new_path(path)
69
78
  dir.join("#{base}.namespaced#{ext}")
70
79
  end
71
80
 
72
- def namespace_file(namespace, path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
81
+ def rubocop_cmd(path, ruby_code) # rubocop:disable Metrics/MethodLength
82
+ result = Rubyists::Namespacer.cmd.run!(:rubocop,
83
+ '-A',
84
+ '--stdin',
85
+ path.basename.to_s,
86
+ '--stderr',
87
+ input: ruby_code,
88
+ only_output_on_error: true)
89
+ if result.failure?
90
+ warn "Rubocop failed for #{path}:\n#{result.err}"
91
+ if Rubyists::Namespacer.cli_options.fail_rubocop_silently
92
+ warn 'Continuing anyway'
93
+ else
94
+ exit 6
95
+ end
96
+ end
97
+
98
+ result
99
+ end
100
+
101
+ def namespace_file(namespace, path) # rubocop:disable Metrics/MethodLength
102
+ opts = Rubyists::Namespacer.cli_options
73
103
  namespaced = Rubyists::Namespacer.namespace!(path.read, namespace)
74
- write_path = Rubyists::Namespacer.cli_options.in_place ? path : new_path(path)
75
- if Rubyists::Namespacer.cli_options.verbose
104
+ write_path = opts.in_place ? path : new_path(path)
105
+ if opts.verbose
76
106
  msg = "Namespacing #{write_path} with #{namespace}"
77
- msg << ' (in-place)' if Rubyists::Namespacer.cli_options.in_place
107
+ msg << ' (in-place)' if opts.in_place
78
108
  warn msg
79
109
  end
80
- cmd = Rubyists::Namespacer.cmd.run(:rubocop,
81
- '-A',
82
- '--stdin',
83
- write_path.basename.to_s,
84
- '--stderr',
85
- input: namespaced,
86
- only_output_on_error: true)
110
+ cmd = rubocop_cmd(write_path, namespaced)
111
+ return unless cmd&.success?
112
+
113
+ warn "Writing namespaced file to #{write_path}" if opts.verbose
87
114
  write_path.write(cmd.out)
88
115
  end
89
116
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubyists
4
4
  module Namespacer
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.5'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namespacer-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tj (bougyman) Vanderpoel
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-filemagic
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: tty-command
29
43
  requirement: !ruby/object:Gem::Requirement