ruby-edit 0.2.0 → 0.3.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
- SHA1:
3
- metadata.gz: b8ce0b6ad8fbdda4911586a085a0254a4bb03847
4
- data.tar.gz: ff638bfbc7891d379ed818078862698bc097b717
2
+ SHA256:
3
+ metadata.gz: c2db2191f5accfe438db15cc17bddbbe511142d0a8c9cc92e4455f1de826c45b
4
+ data.tar.gz: 3eb45b01ca1b2f90e2ca386b4a42c5bcb364d97f49f88587da531ea561afb145
5
5
  SHA512:
6
- metadata.gz: 9aec4d33402fb366d9a58fba203ae883ee902a66f7a9a8d1c5c813d673f95c6bdb53be1e39af094db3c9d85bcecbc8df94f02f24567c5fe9556a53663d7fa09c
7
- data.tar.gz: 166b3018553d5d2a2773d4890de21375c060cd1896ac80e8826624f287c62b1ca9cd03befbe60f64ed6fc23833eb0a97c264df11474cc1b08bd15882f91680c5
6
+ metadata.gz: e413e5fb3451650e97e22710d00be4dd0d6933df1286e8dfa4e7dce3af29ba1bc32a945025206a6f871050bab6aa96c4c60b5290d4fc2c3ee105618bc43cfeb3
7
+ data.tar.gz: cfa48842fab46ae7cde378a79c0803d654222e47b8e81009995a9cc49e377f66958e4ec6120ddc89c165ea26b4b574c3ebd1f894c31810b6d540549481fa5f6a
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ tags
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-edit (0.2.0)
4
+ ruby-edit (0.3.0)
5
5
  pastel (~> 0.7.2)
6
6
  thor (~> 0.20.0)
7
7
  tty-color (~> 0.4.2)
@@ -66,14 +66,16 @@ GEM
66
66
  simplecov-html (~> 0.10.0)
67
67
  simplecov-html (0.10.2)
68
68
  slop (3.6.0)
69
- strings (0.1.1)
70
- unicode-display_width (~> 1.3.0)
69
+ strings (0.1.4)
70
+ strings-ansi (~> 0.1.0)
71
+ unicode-display_width (~> 1.4.0)
71
72
  unicode_utils (~> 1.4.0)
73
+ strings-ansi (0.1.0)
72
74
  thor (0.20.0)
73
75
  timers (4.1.2)
74
76
  hitimes
75
77
  tty-color (0.4.3)
76
- tty-command (0.8.1)
78
+ tty-command (0.8.2)
77
79
  pastel (~> 0.7.0)
78
80
  tty-config (0.2.0)
79
81
  tty-cursor (0.5.0)
@@ -97,7 +99,7 @@ GEM
97
99
  tty-screen (~> 0.6.4)
98
100
  tty-which (~> 0.3.0)
99
101
  tty-platform (0.1.0)
100
- tty-progressbar (0.15.0)
102
+ tty-progressbar (0.15.1)
101
103
  tty-cursor (~> 0.5.0)
102
104
  tty-screen (~> 0.6.4)
103
105
  unicode-display_width (~> 1.3)
@@ -122,7 +124,7 @@ GEM
122
124
  tty-screen (~> 0.6.4)
123
125
  tty-tree (0.1.0)
124
126
  tty-which (0.3.0)
125
- unicode-display_width (1.3.3)
127
+ unicode-display_width (1.4.0)
126
128
  unicode_utils (1.4.0)
127
129
  wisper (2.0.0)
128
130
 
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # RubyEdit
1
+ [![Gem Version](https://badge.fury.io/rb/ruby-edit.svg)](https://badge.fury.io/rb/ruby-edit)
2
+ [![Build Status](https://travis-ci.org/finn-francis/ruby-edit.svg?branch=master)](https://travis-ci.org/finn-francis/ruby-edit)
2
3
 
3
- ALPHA RELEASE
4
+ # RubyEdit
4
5
 
5
6
  RubyEdit is a simple commandline app that allows you to edit grep results in one file.
6
7
 
@@ -1,2 +1,3 @@
1
1
  ---
2
+ grep_options: ir
2
3
  editor: vim
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ruby_extensions/string'
3
4
  require 'ruby_edit/version'
4
5
  require 'ruby_edit/configuration'
5
6
 
@@ -19,9 +19,8 @@ module RubyEdit
19
19
  map %w[--version -v] => :version
20
20
 
21
21
  desc 'grep', 'search for an expression in your directory'
22
- method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information'
23
22
  method_option :expression, aliases: %w[-e --expression], type: :string,
24
- desc: 'the grep expression'
23
+ desc: 'the grep expression', required: true
25
24
  method_option :path, aliases: %w[-p --path], type: :string, desc: 'the path you want to search'
26
25
  def grep(*)
27
26
  if options[:help]
@@ -38,6 +37,8 @@ module RubyEdit
38
37
  method_option :help, aliases: '-h', type: :boolean, desc: 'Display useage information'
39
38
  method_option :editor, aliases: %w[-e --editor], type: :string,
40
39
  desc: 'Set or view your default text editor'
40
+ method_option :grep_options, aliases: %w[-o --grep-options], type: :string,
41
+ description: 'default grep options to refine your searches'
41
42
  def configure(*)
42
43
  if options[:help]
43
44
  invoke :help, ['configure']
@@ -50,11 +51,9 @@ module RubyEdit
50
51
  map %w[--configure -c] => :configure
51
52
 
52
53
  desc 'edit', '[Default] Perform a grep and edit the changes in one file'
53
- method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information'
54
54
  method_option :expression, aliases: %w[-e --expression], type: :string,
55
- desc: 'the grep expression'
55
+ desc: 'the grep expression', required: true
56
56
  method_option :path, aliases: %w[-p --path], type: :string, desc: 'the path you want to search'
57
-
58
57
  def edit(*)
59
58
  if options[:help]
60
59
  invoke :help, ['edit']
@@ -5,24 +5,27 @@ require 'ruby_edit'
5
5
  module RubyEdit
6
6
  module Commands
7
7
  class Configure
8
+ CONFIGURATIONS = %i[editor grep_options].freeze
9
+
8
10
  def initialize(options)
9
11
  @options = options
10
12
  end
11
13
 
12
14
  def execute(output: $stdout)
13
- # This may need to be made dynamic if more configuration options are added
14
- if editor == 'editor'
15
- output.puts RubyEdit.config.editor
16
- else
17
- RubyEdit.config.editor = editor
18
- output.puts "Editor changed to #{editor}"
15
+ options.each do |key, val|
16
+ if val == key.to_s
17
+ output.puts RubyEdit.config.send(key)
18
+ else
19
+ RubyEdit.config.send("#{key}=", val)
20
+ output.puts "#{key.to_s.titleize} changed to #{val}"
21
+ end
19
22
  end
20
23
  end
21
24
 
22
25
  private
23
26
 
24
- def editor
25
- @options[:editor]
27
+ def options
28
+ @options = @options.select { |key, _val| CONFIGURATIONS.include?(key.to_sym) }
26
29
  end
27
30
  end
28
31
  end
@@ -19,7 +19,7 @@ module RubyEdit
19
19
  end
20
20
 
21
21
  def execute
22
- grep_search
22
+ return unless grep_search
23
23
  populate_sourcefile
24
24
  edit_file
25
25
  apply_changes if apply_changes?
@@ -10,16 +10,26 @@ module RubyEdit
10
10
  end
11
11
 
12
12
  def editor
13
- @config.fetch(:editor)&.to_sym || :vim
13
+ @config.fetch(:editor) || 'vim'
14
14
  end
15
15
 
16
16
  def editor=(editor)
17
- @config.set(:editor, value: editor.to_s)
17
+ @config.set(:editor, value: editor)
18
+ write
19
+ end
20
+
21
+ def grep_options
22
+ @config.fetch(:grep_options) || 'ir'
23
+ end
24
+
25
+ def grep_options=(grep_options)
26
+ @config.set(:grep_options, value: grep_options)
18
27
  write
19
28
  end
20
29
 
21
30
  def reset_defaults
22
31
  @config.set(:editor, value: 'vim')
32
+ @config.set(:grep_options, value: 'ir')
23
33
  write
24
34
  end
25
35
 
@@ -7,7 +7,7 @@ module RubyEdit
7
7
  attr_reader :result
8
8
 
9
9
  def initialize(options)
10
- @path = options[:path] || '.'
10
+ @path = options[:path] || '*'
11
11
  @expression = options[:expression]
12
12
  end
13
13
 
@@ -17,7 +17,6 @@ module RubyEdit
17
17
  return false
18
18
  end
19
19
  @result = run "grep -irn #{@path} -e '#{@expression}'" do |out, err|
20
- output << out if out
21
20
  errors << err if err
22
21
  end
23
22
  rescue TTY::Command::ExitError => error
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyEdit
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
6
6
 
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ def titleize
5
+ tr('_', ' ').capitalize
6
+ end
7
+ end
8
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-edit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - finn-francis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-17 00:00:00.000000000 Z
11
+ date: 2018-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -384,6 +384,7 @@ files:
384
384
  - lib/ruby_edit/templates/.gitkeep
385
385
  - lib/ruby_edit/version.rb
386
386
  - lib/ruby_edit/writer.rb
387
+ - lib/ruby_extensions/string.rb
387
388
  - ruby-edit.gemspec
388
389
  homepage: https://github.com/finn-francis/ruby-edit
389
390
  licenses:
@@ -405,7 +406,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
405
406
  version: '0'
406
407
  requirements: []
407
408
  rubyforge_project:
408
- rubygems_version: 2.5.2
409
+ rubygems_version: 2.7.6
409
410
  signing_key:
410
411
  specification_version: 4
411
412
  summary: Edit grep results in one file