grepg 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +51 -18
- data/lib/grepg/formatter.rb +11 -3
- data/lib/grepg/parser.rb +54 -17
- data/lib/grepg/version.rb +1 -1
- data/spec/grepg/parser_spec.rb +49 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5768dab30082e58dce3e5b49cdb76a29b8fa9da
|
4
|
+
data.tar.gz: ddf1a091efc9ad7eee32d37e3d65ef40696b1127
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2bfe0fa4f80d0c1a6baa4cbd25d2bdc5bff1e5c59f1effaeda4a38bb4a1e8818e642192d13bd15f4d09ea1d3a7f00c0171a3908ee5e858602e993b1e7ca3135
|
7
|
+
data.tar.gz: 73da667814bd9860af347e465933ed7eacc04d376690d832cee8595097c354b529036e0bd2d3486c8cd841e18d6247637d15cdb93ab54c9851267dd778eb69c6
|
data/README.md
CHANGED
@@ -1,33 +1,50 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
grepg
|
2
|
+
===
|
3
3
|
|
4
|
-
`grepg` (pronounced Grep G) is a ruby client for [GrepPage](https://www.greppage.com). It
|
4
|
+
`grepg` (pronounced Grep G) is a ruby client for [GrepPage](https://www.greppage.com). It allows you to access your cheat sheets without leaving the terminal.
|
5
5
|
|
6
|
-
|
7
|
-
To install `grepg` run
|
6
|
+
#Installation
|
7
|
+
To install `grepg` run
|
8
8
|
|
9
|
-
###Examples
|
10
9
|
```
|
10
|
+
gem install grepg
|
11
|
+
```
|
12
|
+
|
13
|
+
#Usage
|
14
|
+
|
15
|
+
```
|
16
|
+
$ grepg --help
|
11
17
|
Usage:
|
12
|
-
grepg user_name topic_name [-s search_term]
|
18
|
+
grepg -u user_name -t topic_name [-s search_term]
|
19
|
+
|
20
|
+
Options:
|
21
|
+
-u, --user=<s> username
|
22
|
+
-t, --topic=<s> topic
|
23
|
+
-s, --search=<s> text to search
|
24
|
+
-c, --colorize, --no-colorize colorize output (default: true)
|
25
|
+
-v, --version Print version and exit
|
26
|
+
-h, --help Show this message
|
27
|
+
|
28
|
+
Examples:
|
29
|
+
grepg -u evidanary -t css
|
30
|
+
greppg -u evidanary -t css -s color
|
31
|
+
|
32
|
+
Defaults:
|
33
|
+
To set default user, create a file in ~/.grepg.yml with
|
34
|
+
default_user: test
|
13
35
|
```
|
14
36
|
|
15
|
-
|
37
|
+
|
38
|
+
For example, to get all cheats for the `git` topic for user `kdavis`
|
16
39
|
|
17
40
|
```
|
18
|
-
$ grepg
|
19
|
-
User:
|
41
|
+
$ grepg -u evidanary -t git
|
42
|
+
User: evidanary, Topic: git
|
20
43
|
push tags to remote / Github
|
21
44
|
git push --tags
|
22
45
|
|
23
46
|
remove delete tag
|
24
47
|
git tag -d v0.0.8
|
25
|
-
|
26
|
-
list branches that have not been merged
|
27
|
-
git branch --no-merged
|
28
|
-
|
29
|
-
list branches merged into master
|
30
|
-
git branch --merged master
|
31
48
|
...
|
32
49
|
|
33
50
|
```
|
@@ -35,7 +52,7 @@ git branch --merged master
|
|
35
52
|
Search for a specific string
|
36
53
|
|
37
54
|
```
|
38
|
-
$ grepg kdavis git -s stash
|
55
|
+
$ grepg -u kdavis -t git -s stash
|
39
56
|
User: kdavis, Topic: git, Search-Term: stash
|
40
57
|
TO apply your changes
|
41
58
|
git stash --apply
|
@@ -47,8 +64,24 @@ Git stash
|
|
47
64
|
git stash
|
48
65
|
```
|
49
66
|
|
67
|
+
#Defaults File
|
68
|
+
Setup defaults in `~/.grepg.yml`
|
69
|
+
|
70
|
+
```
|
71
|
+
user: evidanary
|
72
|
+
colorize: true
|
73
|
+
```
|
74
|
+
|
75
|
+
Now, you can access client with
|
76
|
+
|
77
|
+
```
|
78
|
+
$ grepg -t bootstrap
|
79
|
+
User: evidanary, Topic: bootstrap
|
80
|
+
...
|
81
|
+
```
|
82
|
+
|
50
83
|
##Development
|
51
|
-
To
|
84
|
+
To execute tests run ```bundle exec rake spec```. To install the gem locally, first build it using ```bundle exec rake build```. Then install the gem ```gem install pkg/grepg-0.0.1.gem```
|
52
85
|
|
53
86
|
##License
|
54
87
|
grepg is under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/lib/grepg/formatter.rb
CHANGED
@@ -3,10 +3,18 @@ module GrepPage
|
|
3
3
|
class Formatter
|
4
4
|
# Displays an array of cheats
|
5
5
|
# TODO: Highlight search term
|
6
|
-
|
6
|
+
DESCRIPTION_COLOR= :green
|
7
|
+
COMMAND_COLOR= :blue
|
8
|
+
def self.cheat_rows(cheats, search_term, colorize)
|
7
9
|
cheats.map do |cheat|
|
8
|
-
|
9
|
-
|
10
|
+
description = cheat[:description]
|
11
|
+
command = cheat[:command]
|
12
|
+
if colorize
|
13
|
+
description = description.colorize(DESCRIPTION_COLOR)
|
14
|
+
command = command.colorize(COMMAND_COLOR)
|
15
|
+
end
|
16
|
+
puts description
|
17
|
+
puts command
|
10
18
|
puts
|
11
19
|
end
|
12
20
|
end
|
data/lib/grepg/parser.rb
CHANGED
@@ -1,36 +1,69 @@
|
|
1
1
|
require 'trollop'
|
2
2
|
require 'rest-client'
|
3
|
+
require 'yaml'
|
4
|
+
require_relative 'version'
|
3
5
|
|
4
6
|
# This class parses commandline arguments
|
5
7
|
module GrepPage
|
6
8
|
class Parser
|
7
9
|
def initialize(args)
|
10
|
+
default_config = self.class.get_default_config
|
8
11
|
parser = Trollop::Parser.new do
|
12
|
+
opt :user,
|
13
|
+
"username",
|
14
|
+
:type => :string,
|
15
|
+
:default => default_config['user'],
|
16
|
+
:short => "-u"
|
17
|
+
opt :topic,
|
18
|
+
"topic",
|
19
|
+
:type => :string,
|
20
|
+
:required => true,
|
21
|
+
:short => "-t"
|
9
22
|
opt :search,
|
10
23
|
"text to search",
|
11
24
|
:type => :string,
|
12
25
|
:required => false,
|
13
26
|
:short => "-s"
|
27
|
+
opt :colorize,
|
28
|
+
"colorize output",
|
29
|
+
:type => :boolean,
|
30
|
+
:default => default_config['colorize'],
|
31
|
+
:short => "-c"
|
32
|
+
version "grepg version #{GrepPage::VERSION}"
|
14
33
|
banner <<-EOS
|
15
34
|
|
16
35
|
Usage:
|
17
|
-
grepg user_name topic_name [-s search_term]
|
36
|
+
grepg -u user_name -t topic_name [-s search_term]
|
18
37
|
|
19
38
|
Examples:
|
20
|
-
grepg
|
21
|
-
greppg
|
39
|
+
grepg -u evidanary -t css
|
40
|
+
greppg -u evidanary -t css -s color
|
41
|
+
|
42
|
+
Defaults:
|
43
|
+
To set defaults, create a file in ~/.grepg.yml with
|
44
|
+
user: test
|
45
|
+
colorize: true
|
22
46
|
EOS
|
23
47
|
end
|
24
48
|
|
25
49
|
@opts = Trollop::with_standard_exception_handling parser do
|
26
|
-
raise Trollop::HelpNeeded if args.size < 2 # show help screen
|
27
50
|
parser.parse args
|
28
51
|
end
|
29
52
|
|
30
|
-
|
31
|
-
@
|
32
|
-
@topic = leftovers.shift
|
53
|
+
@user = @opts[:user]
|
54
|
+
@topic = @opts[:topic]
|
33
55
|
@search_term = @opts[:search]
|
56
|
+
@colorize = @opts[:colorize]
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.get_default_config
|
60
|
+
file = self.default_file_name
|
61
|
+
file ? YAML.load(IO.read(file)) : {}
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.default_file_name
|
65
|
+
file = ENV['HOME'] + '/.grepg.yml'
|
66
|
+
File.exist?(file) ? file : nil
|
34
67
|
end
|
35
68
|
|
36
69
|
def get_all_topics(user)
|
@@ -54,29 +87,33 @@ Examples:
|
|
54
87
|
end
|
55
88
|
end
|
56
89
|
|
57
|
-
def
|
58
|
-
headers = ["User: #{
|
59
|
-
headers << "Search-Term: #{
|
90
|
+
def process_args(user, topic, search_term, colorize)
|
91
|
+
headers = ["User: #{user}", "Topic: #{topic}"]
|
92
|
+
headers << "Search-Term: #{search_term}" if search_term
|
60
93
|
puts headers.join(", ")
|
61
94
|
|
62
95
|
begin
|
63
|
-
topics = get_all_topics(
|
96
|
+
topics = get_all_topics(user)
|
64
97
|
rescue RestClient::ResourceNotFound
|
65
98
|
puts "That username does not exist"
|
66
|
-
|
99
|
+
raise "Unable to find user"
|
67
100
|
end
|
68
101
|
|
69
|
-
topic = filter_topics(topics,
|
102
|
+
topic = filter_topics(topics, topic)
|
70
103
|
if topic.nil? || topic.empty?
|
71
104
|
puts "Can't find that topic. Choose one of the following"
|
72
105
|
puts topics.map{|t| t[:name]}
|
73
|
-
|
106
|
+
raise "Unable to find topic"
|
74
107
|
end
|
75
108
|
|
76
|
-
cheats = get_cheats(
|
77
|
-
cheats = filter_cheats(cheats,
|
109
|
+
cheats = get_cheats(user, topic[:id])
|
110
|
+
cheats = filter_cheats(cheats, search_term) if search_term
|
78
111
|
|
79
|
-
GrepPage::Formatter.cheat_rows(cheats,
|
112
|
+
GrepPage::Formatter.cheat_rows(cheats, search_term, colorize)
|
113
|
+
end
|
114
|
+
|
115
|
+
def run!
|
116
|
+
process_args(@user, @topic, @search_term, @colorize)
|
80
117
|
end
|
81
118
|
end
|
82
119
|
end
|
data/lib/grepg/version.rb
CHANGED
data/spec/grepg/parser_spec.rb
CHANGED
@@ -1,20 +1,67 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'yaml'
|
2
3
|
require_relative '../../lib/grepg.rb'
|
3
4
|
|
4
5
|
describe GrepPage::Parser do
|
5
6
|
describe '.initialize' do
|
6
7
|
context "expected behavior" do
|
7
8
|
it "returns a set of cheats when username and topic are given" do
|
8
|
-
parser = GrepPage::Parser.new(
|
9
|
+
parser = GrepPage::Parser.new('-u kdavis -t css'.split(' '))
|
9
10
|
output = capture_stdout { parser.run! }
|
10
11
|
expect(output).to match(/colors/)
|
11
12
|
end
|
12
13
|
|
13
14
|
it "returns a set of cheats when username, topic and search term are given" do
|
14
|
-
parser = GrepPage::Parser.new(
|
15
|
+
parser = GrepPage::Parser.new('-u kdavis -t css -s colors'.split(' '))
|
15
16
|
output = capture_stdout { parser.run! }
|
16
17
|
expect(output).to match(/colors/)
|
17
18
|
end
|
19
|
+
|
20
|
+
# Test if we are seeing colors in the output
|
21
|
+
# This is blue - "\e[0;34;49mThis is blue\e[0m"
|
22
|
+
it "colorizes output of the result" do
|
23
|
+
parser = GrepPage::Parser.new('-u kdavis -t css -c'.split(' '))
|
24
|
+
output = capture_stdout { parser.run! }
|
25
|
+
expect(output.inspect).to include("\\e[0;34;49m")
|
26
|
+
end
|
27
|
+
|
28
|
+
# Test if defaut file gets read
|
29
|
+
it "reads username from the defaults file" do
|
30
|
+
expect(File).to receive(:exist?).and_return(true)
|
31
|
+
expect(IO).to receive(:read).with(ENV['HOME'] + '/.grepg.yml').and_return({
|
32
|
+
"user" => "kdavis"
|
33
|
+
}.to_yaml)
|
34
|
+
parser = GrepPage::Parser.new('-t css'.split(' '))
|
35
|
+
expect(parser.instance_variable_get(:@opts)[:user]).to eq('kdavis')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#default_file_name' do
|
41
|
+
it('returns nil if ~/.grepg.yml doesnt exist') do
|
42
|
+
expect(File).to receive(:exist?).and_return(false)
|
43
|
+
expect(GrepPage::Parser.default_file_name).to be(nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
it('returns filename if ~/.grepg.yml exists') do
|
47
|
+
expect(File).to receive(:exist?).and_return(true)
|
48
|
+
expect(GrepPage::Parser.default_file_name).to eq(ENV['HOME'] + '/.grepg.yml')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#get_default_config' do
|
53
|
+
it('returns empty hash if ~/.grepg.yml doesnt exist') do
|
54
|
+
expect(File).to receive(:exist?).and_return(false)
|
55
|
+
expect(GrepPage::Parser.get_default_config).to eq({})
|
56
|
+
end
|
57
|
+
|
58
|
+
it('returns parses YML if ~/.grepg.yml exists') do
|
59
|
+
default_contents = {
|
60
|
+
"user" => "test"
|
61
|
+
}
|
62
|
+
expect(File).to receive(:exist?).and_return(true)
|
63
|
+
expect(IO).to receive(:read).and_return(default_contents.to_yaml)
|
64
|
+
expect(GrepPage::Parser.get_default_config).to eq(default_contents)
|
18
65
|
end
|
19
66
|
end
|
20
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grepg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yash Ranadive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.4.1
|
139
|
+
rubygems_version: 2.4.5.1
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: A ruby client to access greppage.com from the commandline
|