narkisr-snipplr 0.0.5 → 0.0.6
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.
- data/lib/interface/bash_api.rb +18 -11
- metadata +1 -1
data/lib/interface/bash_api.rb
CHANGED
@@ -59,17 +59,21 @@ end
|
|
59
59
|
|
60
60
|
class BashAPI
|
61
61
|
attr_reader :entry
|
62
|
+
|
63
|
+
def initialize
|
64
|
+
@flagsToActions={
|
65
|
+
:d => proc{@entry.delete(@f.d)} , :g=>proc{puts @entry.get_content(@f.g).source},
|
66
|
+
:l=>proc{@entry.find_all_entries.each{|e| puts e.eid+' '+e.title}},
|
67
|
+
:c=>proc{post_request}
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
62
71
|
def process
|
63
72
|
@f = ARGV.flags
|
64
73
|
FileUtils.mkdir(ENV['HOME']+'/.snipplr') if !File.exist?(ENV['HOME']+'/.snipplr')
|
65
74
|
key=(@f.key ? @f.key : (IO.read(ENV['HOME']+'/.snipplr/api_key')).chomp!)
|
66
75
|
@entry=SnipplrEntry.new(key)
|
67
|
-
|
68
|
-
@meta=eval('{'+@f.meta+'}') if @f.meta
|
69
|
-
delete_entry if @f.d
|
70
|
-
post_request if @f.c
|
71
|
-
print_entry if @f.g
|
72
|
-
puts 'Use the -h option for help' if !@f.values.find { |val| val}
|
76
|
+
process_calls
|
73
77
|
end
|
74
78
|
|
75
79
|
private
|
@@ -86,12 +90,15 @@ class BashAPI
|
|
86
90
|
@entry.post_entry(@meta)
|
87
91
|
end
|
88
92
|
|
89
|
-
def
|
90
|
-
|
93
|
+
def proc(&proc)
|
94
|
+
proc
|
91
95
|
end
|
92
|
-
|
93
|
-
def
|
94
|
-
@
|
96
|
+
|
97
|
+
def process_calls
|
98
|
+
@meta=eval('{'+@f.meta+'}') if @f.meta
|
99
|
+
@flagsToActions.each_pair { |flag,act| act.call if @f.send(flag) }
|
100
|
+
puts 'Use the -h option for help' if !@f.values.find { |val| val}
|
95
101
|
end
|
96
102
|
|
103
|
+
|
97
104
|
end
|