snipper 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,15 +15,16 @@ class MyCLI<Thor
15
15
 
16
16
  To create a new snippet with a file from STDIN:
17
17
 
18
- $ cat files1 | snipper add --lang=php
18
+ $ cat files1 | snipper add
19
19
 
20
20
  There is also a shortcut for supplying files from STDIN:
21
21
 
22
- $ cat file1 | snipper --lang=php
22
+ $ cat file1 | snipper
23
23
  D
24
24
  option :syntax, :desc => "Language to use for the new snippet", :default => "ruby", :type => :string, :aliases => ["-l", "--lang", "-s"]
25
+ option :description, :desc => "Textual description for this snippet", :default => nil, :type => :string, :aliases => ["-d"]
25
26
  def add(file1=nil, file2=nil, file3=nil, file4=nil, file5=nil)
26
- puts Snipper::Util.new([file1, file2, file3, file4, file5].compact, options[:syntax])
27
+ puts Snipper::Util.new([file1, file2, file3, file4, file5].compact, options["syntax"], options["description"])
27
28
  end
28
29
 
29
30
  desc "append [SNIPPET] [FILE1..5]", "appends a file to an existing snippet"
@@ -32,11 +33,12 @@ class MyCLI<Thor
32
33
 
33
34
  $ snipper append 123 file1 file2 file3 file4 file5 --lang=php
34
35
 
35
- $ cat file1 | snipper append 123 --lang=php
36
+ $ cat file1 | snipper append 123
36
37
  D
37
38
  option :syntax, :desc => "Language to use for the new snippet", :default => "ruby", :type => :string, :aliases => ["-l", "--lang", "-s"]
39
+ option :description, :desc => "Textual description for this snippet", :default => nil, :type => :string, :aliases => ["-d"]
38
40
  def append(snippet, file1=nil, file2=nil, file3=nil, file4=nil, file5=nil)
39
- puts Snipper::Util.append(snippet, [file1, file2, file3, file4, file5].compact, options[:syntax])
41
+ puts Snipper::Util.append(snippet, [file1, file2, file3, file4, file5].compact, options["syntax"], options["description"])
40
42
  end
41
43
 
42
44
  desc "delete [SNIPPET]", "deletes an existing snippet"
@@ -54,6 +56,11 @@ class MyCLI<Thor
54
56
  puts Snipper::Util.view(snippet)
55
57
  end
56
58
 
59
+ desc "search [STRING]", "Search snippets"
60
+ def search(string)
61
+ Snipper::Util.search(string)
62
+ end
63
+
57
64
  desc "languages", "list known languages"
58
65
  def languages
59
66
  Snipper::Util.list_langs
@@ -10,7 +10,16 @@ class Snipper
10
10
  snip.delete!
11
11
  end
12
12
 
13
- def self.new(snippet, syntax)
13
+ def self.search(string)
14
+ snipper = Snipper.new
15
+
16
+ Dir.chdir(Config[:snippets_dir]) do
17
+ abort "Refusing to search for strings with ` in them" if string.match("'")
18
+ system(Config[:grep].gsub("%Q%", string))
19
+ end
20
+ end
21
+
22
+ def self.new(snippet, syntax, description)
14
23
  snipper = Snipper.new
15
24
 
16
25
  if STDIN.tty?
@@ -27,11 +36,11 @@ class Snipper
27
36
  txt = STDIN.read
28
37
  end
29
38
 
30
- snip = Snippet.new(txt, {:syntax => syntax})
39
+ snip = Snippet.new(txt, {:syntax => syntax, :description => description})
31
40
  snip.url_for_snippet
32
41
  end
33
42
 
34
- def self.append(snippet_id, snippet, syntax)
43
+ def self.append(snippet_id, snippet, syntax, description)
35
44
  snipper = Snipper.new
36
45
 
37
46
  if STDIN.tty?
@@ -42,7 +51,7 @@ class Snipper
42
51
  txt = STDIN.read
43
52
  end
44
53
 
45
- snip = Snippet.new(txt, {:syntax => syntax, :snippet => snippet_id})
54
+ snip = Snippet.new(txt, {:syntax => syntax, :snippet => snippet_id, :description => description})
46
55
  snip.url_for_snippet
47
56
  end
48
57
 
@@ -1,3 +1,3 @@
1
1
  class Snipper
2
- VERSION="0.0.3"
2
+ VERSION="0.0.4"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snipper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - R.I.Pienaar
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-03 00:00:00 +01:00
18
+ date: 2012-06-20 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency