reenrb 0.2.2 → 0.3.2
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 +4 -4
- data/README.md +17 -17
- data/Rakefile +4 -4
- data/bin/reen +78 -13
- data/lib/reenrb/changes.rb +9 -1
- data/lib/reenrb/changes_file.rb +21 -6
- data/lib/reenrb/reen.rb +4 -12
- data/lib/reenrb/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c68c858766fec42e13e8d8d70ea0c60fa1a0e56c445aa148645931ed95ab1bb
|
4
|
+
data.tar.gz: df29a4fdad7a40025640bfb85826e1a38487423656cd59cb0e72fd897a28128c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bd3acf09e88085731e698a952d20d8368a6b1eebfaadab2ac0128dff60b1f66c6ba635c30a4ef96b00b7d15b1aeac8d0c7e91f147971be38d0c26448138edab
|
7
|
+
data.tar.gz: ab1fdc1f3dab04893568aa4223cf05e6e99731e0517f241f61bcd1ccd74bd22fb40185d7b775b1175e09354a279e1a218d22a0d4afa3c96a7680c40ffbbba6b2
|
data/README.md
CHANGED
@@ -14,26 +14,29 @@ Or add this line to your Ruby application's Gemfile for programmatic use:
|
|
14
14
|
gem 'reenrb'
|
15
15
|
```
|
16
16
|
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle install
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install reenrb
|
24
|
-
|
25
17
|
## Usage
|
26
18
|
|
27
19
|
### Command line
|
28
20
|
|
29
21
|
From command line, run `reen` with file list:
|
30
22
|
|
31
|
-
reen [
|
23
|
+
reen files [options]
|
24
|
+
|
25
|
+
where `files` are a list of files or wildcard pattern (defaults to `*`; see examples)
|
26
|
+
|
27
|
+
Options include:
|
28
|
+
|
29
|
+
- `--help` or `-h`' to see options help
|
30
|
+
- `--editor EDITOR` or `-e EDITOR`' to set the editor (defaults to $VISUAL or $EDITOR otherwise) such as `emacs` or `vi`. For Visual Studio Code use `'code -w'` to block until editor finishes.
|
31
|
+
- `--review` or `-r` request to review and confirm changes
|
32
32
|
|
33
33
|
Examples:
|
34
34
|
|
35
|
-
reen *
|
36
|
-
reen
|
35
|
+
reen # reen all files (*)
|
36
|
+
reen **/* # reen all files in all subfolders
|
37
|
+
reen myfolder/**/*.mov # reen all mov files in subfolders
|
38
|
+
reen *.md --editor vi # reen all markdown files using vi
|
39
|
+
reen --editor 'code -w' # reen all markdown files using vscode
|
37
40
|
|
38
41
|
### Ruby application
|
39
42
|
|
@@ -45,13 +48,10 @@ require 'reenrb'
|
|
45
48
|
glob = Dir.glob("*")
|
46
49
|
reen = Reenrb::Reen.new(editor: nil)
|
47
50
|
|
48
|
-
reen.execute(glob) do |
|
49
|
-
lines = File.read(tmpfile_path).split("\n")
|
50
|
-
|
51
|
+
reen.execute(glob) do |file|
|
51
52
|
# Rename LICENSE.txt -> LICENSE.md
|
52
|
-
index =
|
53
|
-
|
54
|
-
File.write(tmpfile_path, lines.join("\n"))
|
53
|
+
index = file.list.index { |l| l.include? "LICENSE.txt" }
|
54
|
+
file.list[index] = file.list[index].gsub("txt", "md")
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require "bundler/gem_tasks"
|
|
4
4
|
require "rake/testtask"
|
5
5
|
|
6
6
|
Rake::TestTask.new(:spec) do |t|
|
7
|
-
t.libs << "
|
7
|
+
t.libs << "spec"
|
8
8
|
t.libs << "lib"
|
9
9
|
t.test_files = FileList["spec/**/spec_*.rb"]
|
10
10
|
end
|
@@ -14,18 +14,18 @@ task :respec do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
namespace :example do
|
17
|
-
task :
|
17
|
+
task :helper do
|
18
18
|
require_relative "spec/fixture_helper"
|
19
19
|
end
|
20
20
|
|
21
21
|
desc "Recreates the example fixture folder"
|
22
|
-
task :recreate => :
|
22
|
+
task :recreate => :helper do
|
23
23
|
FixtureHelper.recreate_example_dir
|
24
24
|
puts "Example fixture recreated"
|
25
25
|
end
|
26
26
|
|
27
27
|
desc "Deletes the example fixture folder"
|
28
|
-
task :remove => :
|
28
|
+
task :remove => :helper do
|
29
29
|
FixtureHelper.remove_example_dirs
|
30
30
|
puts "Example fixture removed"
|
31
31
|
end
|
data/bin/reen
CHANGED
@@ -1,22 +1,87 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
EDITOR_MSG = "Editor not set in $EDITOR or $VISUAL -- please set one of those environment variables"
|
5
|
-
|
6
|
-
def exit_with_error(err)
|
7
|
-
puts err
|
8
|
-
exit(false)
|
9
|
-
end
|
10
|
-
|
11
4
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
12
5
|
require "reenrb"
|
6
|
+
require "optparse"
|
7
|
+
|
8
|
+
# Reen command line application
|
9
|
+
class ReenCLI
|
10
|
+
EDITOR_MSG = "Editor not set in $EDITOR or $VISUAL -- please set one of those environment variables"
|
11
|
+
Options = Struct.new(:editor, :review) do
|
12
|
+
def initialize(editor: nil, review: false)
|
13
|
+
editor ||= ENV["VISUAL"] || ENV["EDITOR"] # rubocop:disable Style/FetchEnvVar
|
14
|
+
super(editor, review)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :options, :files
|
19
|
+
|
20
|
+
def initialize(args)
|
21
|
+
@options = Options.new
|
22
|
+
optparse = OptionParser.new { |parser| setup_options(parser) }
|
23
|
+
optparse.parse!(args, into: @options)
|
24
|
+
|
25
|
+
exit_with_msg(EDITOR_MSG) unless options.editor
|
26
|
+
|
27
|
+
@files = args.empty? ? Dir.glob("*") : args
|
28
|
+
rescue OptionParser::InvalidOption => e
|
29
|
+
puts "#{e.message}\n\n"
|
30
|
+
exit_with_msg(optparse)
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_options(parser)
|
34
|
+
parser.banner = "Usage: reen files [options]"
|
35
|
+
parser.version = Reenrb::VERSION
|
13
36
|
|
14
|
-
|
15
|
-
|
16
|
-
exit_with_error(EDITOR_MSG) if editor.empty?
|
37
|
+
parser.on("-e", "--editor EDITOR", "Specify EDITOR to use")
|
38
|
+
parser.on("-r", "--review", "Require review and confirmation of changes")
|
17
39
|
|
18
|
-
|
40
|
+
parser.on("-h", "--help", "Show help for options") do
|
41
|
+
exit_with_msg(parser)
|
42
|
+
end
|
43
|
+
end
|
19
44
|
|
20
|
-
|
45
|
+
def exit_with_msg(message)
|
46
|
+
puts message
|
47
|
+
exit(false)
|
48
|
+
end
|
21
49
|
|
22
|
-
|
50
|
+
def review_changes
|
51
|
+
puts
|
52
|
+
puts @requests.change_requested.summarize
|
53
|
+
print "\nContinue? (y/n) "
|
54
|
+
confirmation = %w[y yes].include?($stdin.gets.chomp.downcase)
|
55
|
+
exit_with_msg("Nothing changed") unless confirmation
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_inputs
|
59
|
+
@files = files.empty? ? Dir.glob("*") : files
|
60
|
+
exit_with_msg(EDITOR_MSG) unless options.editor
|
61
|
+
end
|
62
|
+
|
63
|
+
def user_review?
|
64
|
+
@options.review && @requests.changes_requested?
|
65
|
+
end
|
66
|
+
|
67
|
+
def call
|
68
|
+
@requests = Reenrb::Reen.new(editor: options.editor).request(files)
|
69
|
+
review_changes if user_review?
|
70
|
+
|
71
|
+
changes = @requests
|
72
|
+
.execute_all
|
73
|
+
.change_requested
|
74
|
+
|
75
|
+
if user_review? && changes.all_executed?
|
76
|
+
puts "Changes made"
|
77
|
+
else
|
78
|
+
puts changes.summarize
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
begin
|
84
|
+
ReenCLI.new(ARGV).call
|
85
|
+
rescue Reenrb::Error => e
|
86
|
+
puts "#{e.message}\n"
|
87
|
+
end
|
data/lib/reenrb/changes.rb
CHANGED
@@ -11,7 +11,7 @@ module Reenrb
|
|
11
11
|
@list = changes_list
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def execute_all
|
15
15
|
@list.map(&:execute)
|
16
16
|
self
|
17
17
|
end
|
@@ -42,6 +42,14 @@ module Reenrb
|
|
42
42
|
Changes.new(@list.select(&:executed?))
|
43
43
|
end
|
44
44
|
|
45
|
+
def failed
|
46
|
+
Changes.new(@list.select(&:failed?))
|
47
|
+
end
|
48
|
+
|
49
|
+
def any?
|
50
|
+
!@list.empty?
|
51
|
+
end
|
52
|
+
|
45
53
|
def count
|
46
54
|
@list.size
|
47
55
|
end
|
data/lib/reenrb/changes_file.rb
CHANGED
@@ -5,22 +5,37 @@ require "tempfile"
|
|
5
5
|
module Reenrb
|
6
6
|
# Manages a temporary file with requested changes
|
7
7
|
class ChangesFile
|
8
|
+
INSTRUCTIONS = <<~COMMENTS
|
9
|
+
# Edit the names of any files/folders to rename or move them
|
10
|
+
# - Put a preceeding dash to delete a file or empty folder
|
11
|
+
|
12
|
+
COMMENTS
|
13
|
+
|
14
|
+
attr_accessor :list
|
15
|
+
|
8
16
|
def initialize(requested_list)
|
9
17
|
@list_file = Tempfile.new("reenrb-")
|
18
|
+
@list_file.write(INSTRUCTIONS)
|
10
19
|
@list_file.write(requested_list.join("\n"))
|
11
20
|
@list_file.close
|
12
21
|
end
|
13
22
|
|
14
|
-
def
|
15
|
-
|
23
|
+
def allow_changes(editor, &block)
|
24
|
+
await_editor(editor) if editor
|
25
|
+
@list = File.read(path).split("\n").map(&:strip)
|
26
|
+
.reject { |line| line.start_with?("#") || line.empty? }
|
27
|
+
|
28
|
+
block&.call(self)
|
29
|
+
@list
|
16
30
|
end
|
17
31
|
|
18
|
-
|
19
|
-
|
20
|
-
|
32
|
+
private
|
33
|
+
|
34
|
+
def path
|
35
|
+
@list_file.path
|
21
36
|
end
|
22
37
|
|
23
|
-
def
|
38
|
+
def await_editor(editor)
|
24
39
|
`#{editor} #{@list_file.path}`
|
25
40
|
end
|
26
41
|
end
|
data/lib/reenrb/reen.rb
CHANGED
@@ -6,7 +6,7 @@ module Reenrb
|
|
6
6
|
# Reenrb::Reen.new(editor: "code -w").call("spec/fixtures/example/*")
|
7
7
|
# Reenrb::Reen.new(editor: nil).call("spec/fixtures/example/*") { ... }
|
8
8
|
class Reen
|
9
|
-
DEL_ERROR = "Do not
|
9
|
+
DEL_ERROR = "Do not remove any file/folder names (no changes made)"
|
10
10
|
|
11
11
|
attr_reader :changes
|
12
12
|
|
@@ -15,16 +15,8 @@ module Reenrb
|
|
15
15
|
@options = options
|
16
16
|
end
|
17
17
|
|
18
|
-
def request(original_list, &block)
|
19
|
-
changed_list = ChangesFile.new(original_list).allow_changes
|
20
|
-
file.blocking_edit(@editor) if @editor
|
21
|
-
|
22
|
-
if block
|
23
|
-
lines = File.read(file.path).split("\n")
|
24
|
-
new_lines = block.call(lines) || lines
|
25
|
-
File.write(file.path, new_lines.join("\n"))
|
26
|
-
end
|
27
|
-
end
|
18
|
+
def request(original_list, &block)
|
19
|
+
changed_list = ChangesFile.new(original_list).allow_changes(@editor, &block)
|
28
20
|
|
29
21
|
raise(Error, DEL_ERROR) if changed_list.size != original_list.size
|
30
22
|
|
@@ -34,7 +26,7 @@ module Reenrb
|
|
34
26
|
|
35
27
|
def execute(original_list, &block)
|
36
28
|
@changes ||= request(original_list, &block)
|
37
|
-
@changes = @changes.
|
29
|
+
@changes = @changes.execute_all
|
38
30
|
end
|
39
31
|
|
40
32
|
private
|
data/lib/reenrb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reenrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soumya Ray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -105,7 +105,6 @@ files:
|
|
105
105
|
- ".rubocop.yml"
|
106
106
|
- CHANGELOG.md
|
107
107
|
- Gemfile
|
108
|
-
- Gemfile.lock
|
109
108
|
- LICENSE.txt
|
110
109
|
- README.md
|
111
110
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
reenrb (0.2.2)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.4.2)
|
10
|
-
ffi (1.15.5)
|
11
|
-
json (2.6.2)
|
12
|
-
listen (3.7.1)
|
13
|
-
rb-fsevent (~> 0.10, >= 0.10.3)
|
14
|
-
rb-inotify (~> 0.9, >= 0.9.10)
|
15
|
-
minitest (5.16.3)
|
16
|
-
minitest-rg (5.2.0)
|
17
|
-
minitest (~> 5.0)
|
18
|
-
parallel (1.22.1)
|
19
|
-
parser (3.1.2.1)
|
20
|
-
ast (~> 2.4.1)
|
21
|
-
rainbow (3.1.1)
|
22
|
-
rake (13.0.6)
|
23
|
-
rb-fsevent (0.11.2)
|
24
|
-
rb-inotify (0.10.1)
|
25
|
-
ffi (~> 1.0)
|
26
|
-
regexp_parser (2.6.0)
|
27
|
-
rerun (0.13.1)
|
28
|
-
listen (~> 3.0)
|
29
|
-
rexml (3.2.5)
|
30
|
-
rubocop (1.38.0)
|
31
|
-
json (~> 2.3)
|
32
|
-
parallel (~> 1.10)
|
33
|
-
parser (>= 3.1.2.1)
|
34
|
-
rainbow (>= 2.2.2, < 4.0)
|
35
|
-
regexp_parser (>= 1.8, < 3.0)
|
36
|
-
rexml (>= 3.2.5, < 4.0)
|
37
|
-
rubocop-ast (>= 1.23.0, < 2.0)
|
38
|
-
ruby-progressbar (~> 1.7)
|
39
|
-
unicode-display_width (>= 1.4.0, < 3.0)
|
40
|
-
rubocop-ast (1.23.0)
|
41
|
-
parser (>= 3.1.1.0)
|
42
|
-
ruby-progressbar (1.11.0)
|
43
|
-
rubyzip (2.3.2)
|
44
|
-
unicode-display_width (2.3.0)
|
45
|
-
|
46
|
-
PLATFORMS
|
47
|
-
arm64-darwin-21
|
48
|
-
x86_64-linux
|
49
|
-
|
50
|
-
DEPENDENCIES
|
51
|
-
minitest (~> 5.0)
|
52
|
-
minitest-rg (~> 5.0)
|
53
|
-
rake (~> 13.0)
|
54
|
-
reenrb!
|
55
|
-
rerun (~> 0.13)
|
56
|
-
rubocop (~> 1.21)
|
57
|
-
rubyzip (~> 2.3)
|
58
|
-
|
59
|
-
BUNDLED WITH
|
60
|
-
2.3.8
|