findr 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -2,14 +2,20 @@
2
2
  require 'pathname'
3
3
  require 'tempfile'
4
4
  require 'optparse'
5
+ require 'yaml'
5
6
 
6
7
  # this is deprecated on 1.9, but still works fine
7
8
  require 'iconv'
8
9
 
10
+ require 'findr/version'
11
+
12
+
9
13
  module Findr
10
14
 
11
15
  class CLI
12
16
 
17
+ CONFIGFILE = '.findr-config'
18
+
13
19
  def colorize(text, color_code)
14
20
  "\e[#{color_code}m#{text}\e[0m"
15
21
  end
@@ -20,8 +26,8 @@ module Findr
20
26
  def blue(text); colorize(text, 34); end
21
27
 
22
28
  def banner
23
- ("Usage: #{Pathname($0).basename} [options] <search regex> [<replacement string>]" + $/) +
24
- red("THIS PROGRAM COMES WITH NO WARRANTY WHATSOEVER. MAKE BACKUPS!")
29
+ red( "FINDR VERSION #{Findr::VERSION}. THIS PROGRAM COMES WITH NO WARRANTY WHATSOEVER. MAKE BACKUPS!") + $/ +
30
+ "Usage: #{Pathname($0).basename} [options] <search regex> [<replacement string>]"
25
31
  end
26
32
 
27
33
  def show_usage
@@ -38,6 +44,15 @@ module Findr
38
44
  options[:glob] = '*'
39
45
  options[:coding] = 'utf-8'
40
46
 
47
+ # options from file, if present
48
+ if File.exists?( CONFIGFILE )
49
+ file_options = YAML.load_file(CONFIGFILE)
50
+ file_options.delete(:save)
51
+ options.merge!( file_options )
52
+ stdout.puts green "Using #{CONFIGFILE}."
53
+ end
54
+
55
+ # parse command line
41
56
  @option_parser = OptionParser.new do |opts|
42
57
  opts.on('-g', '--glob FILE SEARCH GLOB', 'e.g. "*.{rb,erb}"') do |glob|
43
58
  options[:glob] = glob
@@ -45,13 +60,25 @@ module Findr
45
60
  opts.on('-x', '--execute', 'actually execute the replacement') do
46
61
  options[:force] = true
47
62
  end
48
- opts.on('-c', '--coding FILE CODING SYSTEM', 'e.g. "latin-1"') do |coding|
63
+ opts.on('-c', '--coding FILE CODING SYSTEM', 'e.g. "iso-8859-1"') do |coding|
49
64
  options[:coding] = coding
50
65
  end
66
+ opts.on('-s', '--save', "saves your options to #{CONFIGFILE} for future use") do
67
+ options[:save] = true
68
+ end
51
69
  end
52
70
  @option_parser.banner = self.banner
53
71
  @option_parser.parse!( arguments )
54
72
 
73
+ # optionally save the configuration to file
74
+ if options[:save]
75
+ options.delete(:save)
76
+ stdout.puts red "Nothing to save." unless options
77
+ File.open( CONFIGFILE, 'w' ) { |file| YAML::dump( options, file ) }
78
+ stdout.puts green "Saved options to file #{CONFIGFILE}."
79
+ exit
80
+ end
81
+
55
82
  show_usage if arguments.size == 0
56
83
  arguments.clone.each do |arg|
57
84
  if !options[:find]
@@ -64,9 +91,8 @@ module Findr
64
91
  show_usage
65
92
  end
66
93
  end
67
- show_usage if arguments.size != 0
68
-
69
94
 
95
+ show_usage if arguments.size != 0
70
96
  stdout.puts green "File inclusion glob: " + options[:glob]
71
97
  stdout.puts green "Searching for regex " + options[:find].to_s
72
98
 
@@ -1,3 +1,3 @@
1
1
  module Findr
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,54 +1,74 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: findr
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Markus Strauss
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-06-01 00:00:00.000000000 Z
17
+
18
+ date: 2012-06-01 00:00:00 Z
13
19
  dependencies: []
14
- description: ! 'A ruby find and replace tool for batch editing text files.
15
20
 
16
- '
21
+ description: |
22
+ A ruby find and replace tool for batch editing text files.
23
+
17
24
  email: Markus@ITstrauss.eu
18
- executables:
25
+ executables:
19
26
  - findr
20
27
  extensions: []
28
+
21
29
  extra_rdoc_files: []
22
- files:
30
+
31
+ files:
23
32
  - bin/findr
24
33
  - findr-0.0.1.gem
34
+ - findr-0.0.2.gem
25
35
  - findr.gemspec
26
36
  - lib/findr/cli.rb
27
37
  - lib/findr/version.rb
28
38
  - lib/findr.rb
29
39
  homepage: https://github.com/mstrauss/findr
30
40
  licenses: []
41
+
31
42
  post_install_message:
32
43
  rdoc_options: []
33
- require_paths:
44
+
45
+ require_paths:
34
46
  - lib
35
- required_ruby_version: !ruby/object:Gem::Requirement
47
+ required_ruby_version: !ruby/object:Gem::Requirement
36
48
  none: false
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
57
  none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
47
65
  requirements: []
66
+
48
67
  rubyforge_project:
49
- rubygems_version: 1.8.11
68
+ rubygems_version: 1.8.10
50
69
  signing_key:
51
70
  specification_version: 3
52
71
  summary: A ruby find and replace tool for batch editing text files.
53
72
  test_files: []
73
+
54
74
  has_rdoc: