notehub 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a544612171b56a0c9ab74837dea4e5db498504e4
4
- data.tar.gz: 98bf9a23ed60343167c8c74cf72807a3c048f6bc
3
+ metadata.gz: d21b7ea66c163b0650258157c07cfa43d4b30a41
4
+ data.tar.gz: bb941759f69fba5d103cae574cbbe2a5d86fb71a
5
5
  SHA512:
6
- metadata.gz: e015bc3ae3039adcc94ee1fb1244f3e76e43595ae9d227c04167a0656b4c7f0935456110557b690c6b55d9002626a48199c212e7483422ee6433e3339c1f1f4e
7
- data.tar.gz: 8fab969247db02e5057e345f72b05fc1a3a3f4f9118caccb2e3a8fa98995378b208b278151f9e123393e82491c4420dd35981a53e0e06d945bd9e0fb6259b77a
6
+ metadata.gz: 390b9c16dad645c7e705ce50254da3746e18235d495674003832c3f9dd56102c3f9cdf8858906700ffd1984167dc55822b6af4d50d9abad5fa4d427f3436e6c2
7
+ data.tar.gz: c935aa4b6a110b9fd664187cca0ff6b622cbdfdb7367b821e3645d9de6ea70931a19b58e74ab90ee947d9cbd575c2dec0c3cca3d6cf342220047fe7027d507eb
data/bin/notehub CHANGED
@@ -74,6 +74,7 @@ command :create do |c|
74
74
  additional_options[:theme] = options[:theme] ? options[:theme] : nh.default_theme
75
75
  additional_options[:font] = options[:font] ? options[:font] : nh.default_font
76
76
  additional_options[:header_font] = options[:header] ? options[:header] : nh.default_header_font
77
+ additional_options[:file] = File.expand_path(options[:f]) if options[:f]
77
78
 
78
79
  res = nh.new_note(input, options[:p], additional_options)
79
80
 
@@ -97,8 +98,57 @@ end
97
98
  # end
98
99
  # end
99
100
 
101
+ desc 'Create or update from a file'
102
+ arg_name 'file_name'
103
+ command :file do |c|
104
+ c.action do |global_options,options,args|
105
+ id = nil
106
+ input = nil
107
+ pass = nil
108
+ notes = nh.notes['notes']
109
+ notes.each {|k,note|
110
+ if note.has_key?('file')
111
+ if File.basename(note['file']) == File.basename(args[0])
112
+ note['file'] = File.expand_path(args[0])
113
+ nh.store_note(note)
114
+ id = note['id']
115
+ pass = note['pass']
116
+ input = "use_previous"
117
+ break
118
+ end
119
+ end
120
+ }
121
+ if id
122
+ res = nh.update_note(id, input, pass)
123
+ if res
124
+ puts "Note updated"
125
+ else
126
+ puts "Error updating note"
127
+ end
128
+ else
129
+ file = File.expand_path(args[0])
130
+ if File.exists?(file)
131
+ additional_options = {}
132
+ additional_options[:theme] = nh.default_theme
133
+ additional_options[:font] = nh.default_font
134
+ additional_options[:header_font] = nh.default_header_font
135
+ additional_options[:file] = File.expand_path(args[0])
136
+ input = IO.read(file)
137
+ res = nh.new_note(input, nh.default_password, additional_options)
138
+ if res
139
+ puts "Note created"
140
+ else
141
+ puts "Error creating note"
142
+ end
143
+ else
144
+ raise "No such file"
145
+ end
146
+ end
147
+ end
148
+ end
149
+
100
150
  desc 'Update a note'
101
- arg_name 'noteID'
151
+ arg_name 'search_term'
102
152
  command :update do |c|
103
153
  # TODO: Check note db for password if choosing from list
104
154
  c.desc 'ID for note (default: choose from list)'
@@ -113,7 +163,10 @@ command :update do |c|
113
163
 
114
164
  c.desc 'Read input from file'
115
165
  default_value false
116
- c.flag [:f,:file]
166
+ c.flag [:f,:file,'file_name']
167
+
168
+ c.desc 'Update from previously used file (re-use)'
169
+ c.switch [:r,:reuse]
117
170
 
118
171
  c.desc 'Copy resulting url to clipboard'
119
172
  c.switch [:c,:copy]
@@ -125,7 +178,7 @@ command :update do |c|
125
178
  c.switch [:s,:short]
126
179
 
127
180
  c.action do |global_options,options,args|
128
- if options[:f]
181
+ if options[:f] && !options[:r]
129
182
  if File.exists?(File.expand_path(options[:f]))
130
183
  input = IO.read(File.expand_path(options[:f]))
131
184
  else
@@ -133,9 +186,8 @@ command :update do |c|
133
186
  end
134
187
  elsif options[:P]
135
188
  input = %x{pbpaste}
136
- elsif args.length > 0 && args[0] != "-"
137
- input = args.join(" ")
138
- # elsif STDIN.stat.size > 0
189
+ elsif options[:r]
190
+ input = "use_previous"
139
191
  else
140
192
  # puts "Input note text, ^d to submit" unless STDIN.stat.size > 0
141
193
  if RUBY_VERSION.to_f > 1.9
@@ -146,13 +198,26 @@ command :update do |c|
146
198
  # else
147
199
  # raise "No input or text specified for note"
148
200
  end
149
- if options[:id]
150
- id = options[:id]
151
- else
152
- note = nh.choose_note
153
- raise "Error reading selected note" unless note
154
- id = note['id'].strip
201
+
202
+ args = args.join(" ").strip
203
+ note = false
204
+ notes = nh.notes['notes']
205
+ if args =~ /\S\/\S/ && args =~ /^[a-z0-9\/\-]+$/
206
+
207
+ if notes.has_key? (args)
208
+ note = notes[args]
209
+ end
210
+ end
211
+
212
+ unless note
213
+ puts "Choose a note:"
214
+ note = nh.choose_note(args)
155
215
  end
216
+
217
+
218
+ raise "Error reading selected note" unless note
219
+ id = note['id'].strip
220
+
156
221
  res = nh.update_note(id, input, options[:p])
157
222
  raise "Error updating note" unless res
158
223
 
@@ -208,7 +273,8 @@ command :info do |c|
208
273
  out += "Created: #{note['stats']['published']}" + "\n"
209
274
  out += " Edited: #{note['stats']['edited']}" + "\n" if note['stats'].has_key?('edited')
210
275
  out += " Views: #{note['stats']['views']}" + "\n"
211
- out += " ID: #{note['id']}"
276
+ out += " ID: #{note['id']}" + "\n"
277
+ out += " File: #{note['file']}" if note.has_key?('file')
212
278
  end
213
279
  puts out
214
280
 
@@ -161,7 +161,8 @@ class NotehubAPI
161
161
  'url' => res['longURL'],
162
162
  'short' => res['shortURL'],
163
163
  'stats' => note_data['statistics'],
164
- 'pass' => pass || ""
164
+ 'pass' => pass ? pass : "",
165
+ 'file' => options[:file] ? options[:file] : ""
165
166
  }
166
167
  store_note(note)
167
168
  return note
@@ -175,7 +176,26 @@ class NotehubAPI
175
176
  end
176
177
 
177
178
  def update_note(id, text, pass=false)
178
- # TODO: Signature invalid
179
+ note = @notes['notes'][id]
180
+ if note.has_key?('file')
181
+ if text.nil? || text == "use_previous"
182
+ file = File.expand_path(note['file'])
183
+ if File.exists?(file)
184
+ unless text == "use_previous"
185
+ puts "File: #{file}"
186
+ res = ask("Read from file? (Y/n) ", String)
187
+ if res.strip =~ /^y?$/i
188
+ text = IO.read(file)
189
+ end
190
+ else
191
+ text = IO.read(file)
192
+ end
193
+ end
194
+ end
195
+ end
196
+
197
+ return false unless text
198
+
179
199
  params = {}
180
200
  pass ||= @default_password
181
201
  # raise "Password required for update" unless pass
@@ -1,3 +1,3 @@
1
1
  module Notehub
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notehub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name Here
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-14 00:00:00.000000000 Z
11
+ date: 2014-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake