reddit_image_downloader 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## v0.1.0
4
+
5
+ * Adds `-v` and `--version` for printing current version
6
+ * Fixes `-h` and `--help`
7
+
8
+ ## v0.0.1
9
+
10
+ * Initial release, yay!
data/README.md CHANGED
@@ -72,6 +72,15 @@ the help message:
72
72
 
73
73
  $ reddit_image_downloader -h
74
74
 
75
+ ## Automation
76
+
77
+ If you're using this to maintain a library of images for use as wallpapers, you
78
+ probably don't want to have to run the command every day to get the freshest
79
+ images. If you're on OS X, I wrote a `launchd` plist which can run the command
80
+ every few hours.
81
+
82
+ https://gist.github.com/bloudermilk/6943858
83
+
75
84
  ## Contributing
76
85
 
77
86
  1. Fork it
@@ -2,6 +2,10 @@
2
2
 
3
3
  require "reddit_image_downloader"
4
4
 
5
- RedditImageDownloader::Processor.process!(
6
- RedditImageDownloader::OptionParser.parse(ARGV)
7
- )
5
+ parser = RedditImageDownloader::OptionParser.parse!(ARGV)
6
+
7
+ case parser.options[:subcommand]
8
+ when :help then puts parser.docs
9
+ when :version then puts RedditImageDownloader::VERSION
10
+ when :download then RedditImageDownloader::Processor.process!(parser.options)
11
+ end
@@ -1,15 +1,15 @@
1
1
  module RedditImageDownloader
2
- module OptionParser
2
+ class OptionParser
3
3
  PAGES = %W[top new controversial]
4
4
 
5
5
  DEFAULT_OPTIONS = {
6
- show_help: false,
7
6
  subreddits: [],
8
7
  min_width: 0,
9
8
  min_height: 0,
10
9
  destination: Dir.pwd,
11
10
  max_age: nil,
12
11
  page: :top,
12
+ subcommand: :download,
13
13
  }
14
14
 
15
15
  BANNER = "Usage: reddit_image_downloader [options]"
@@ -32,13 +32,33 @@ module RedditImageDownloader
32
32
  DAYS_FORMATS = %W[-a --max-age=DAYS]
33
33
  DAYS_DESC = "Purge files in destination folder older than DAYS days"
34
34
 
35
+ VERSION_FORMATS = %W[-v --version]
36
+ VERSION_DESC = "Print the version of reddit_image_downloader"
37
+
35
38
  HELP_FORMATS = %W[-h --help]
36
39
  HELP_DESC = "Show this message"
37
40
 
38
- def self.parse(args)
39
- options = DEFAULT_OPTIONS.dup
41
+ attr_accessor :options, :args
42
+
43
+ def self.parse!(*args)
44
+ new(*args).tap(&:parse!)
45
+ end
46
+
47
+ def initialize(args)
48
+ @args = args
49
+ @options = DEFAULT_OPTIONS.dup
50
+ end
51
+
52
+ def parse!
53
+ parser.parse!(args)
54
+ end
40
55
 
41
- parser = ::OptionParser.new do |parser|
56
+ def docs
57
+ parser.to_s
58
+ end
59
+
60
+ def parser
61
+ @parser ||= ::OptionParser.new do |parser|
42
62
  parser.banner = BANNER
43
63
 
44
64
  parser.on(*SUBREDDIT_FORMATS, Array, SUBREDDIT_DESC) do |subreddits|
@@ -65,14 +85,14 @@ module RedditImageDownloader
65
85
  options[:max_age] = days
66
86
  end
67
87
 
88
+ parser.on_tail(*VERSION_FORMATS, VERSION_DESC) do
89
+ options[:subcommand] = :version
90
+ end
91
+
68
92
  parser.on_tail(*HELP_FORMATS, HELP_DESC) do
69
- options[:show_help] = true
93
+ options[:subcommand] = :help
70
94
  end
71
95
  end
72
-
73
- parser.parse!(args)
74
-
75
- options
76
96
  end
77
97
  end
78
98
  end
@@ -1,3 +1,3 @@
1
1
  module RedditImageDownloader
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: reddit_image_downloader
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brendan Loudermilk
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-10 00:00:00.000000000 Z
12
+ date: 2013-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -116,6 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - .gitignore
119
+ - CHANGELOG.md
119
120
  - Gemfile
120
121
  - LICENSE.txt
121
122
  - README.md