gisty 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
data/bin/gisty CHANGED
@@ -16,78 +16,16 @@ def cmd name, args = '', description = ''
16
16
  @help << h.ljust(40) + description + "\n"
17
17
  end
18
18
 
19
- cmd :about, '', 'show about gisty' do
20
- puts Gisty::AA
21
- puts
22
- puts 'version: ' + Gisty::VERSION
23
- puts 'url: ' + Gisty::GISTY_URL
24
- end
25
-
26
- cmd :help, '', 'show help' do
27
- puts @help
28
- end
29
-
30
- cmd :list, '', 'show local list' do
31
- list = @g.list
32
- puts '- public gist -'
33
- list[:public].each do |i|
34
- puts "#{i[0]}: #{i[1].join(' ')}"
35
- end
36
- puts '- private gist -'
37
- list[:private].each do |i|
38
- puts "#{i[0]}: #{i[1].join(' ')}"
39
- end
40
- end
41
-
42
- cmd :sync, '', 'sync remote gist (clone all remote gist)' do
43
- @g.sync
44
- puts '---'
45
- puts 'sync finished.'
46
- end
47
-
48
- cmd :sync_delete, '', 'sync remote gist. delete local gist if remote gist was deleted' do
49
- @g.sync true
50
- puts '---'
51
- puts 'sync finished.'
52
- end
53
-
54
- cmd :pull_all, '', 'pull all gist' do
55
- @g.pull_all
56
- puts '---'
57
- puts 'pull_all finished.'
58
- end
59
-
60
- cmd :post, 'file1 file2 ...', 'post new gist' do |fs|
61
- if fs.size > 0
62
- begin
63
- url = @g.create fs
64
- rescue Gisty::InvalidFileException => e
65
- puts "Error: invalid file"
66
- rescue Exception => e
67
- puts "Error: #{e}"
68
- else
69
- id = url.split('/').last
70
- @g.clone id
71
- system "open #{url}" if /darwin/ === RUBY_PLATFORM
72
- end
73
- end
74
- end
75
-
76
- cmd :private_post, 'file1 file2 ...', 'post new private gist' do |fs|
77
- if fs.size > 0
19
+ def load_commnads path
20
+ Dir.glob(File.join(path, '*.rb')).each do |i|
78
21
  begin
79
- url = @g.create fs, :private => true
22
+ load i
80
23
  rescue Exception => e
81
- puts "Error: #{e}"
82
- else
83
- system "open #{url}" if /darwin/ === RUBY_PLATFORM
84
- id = url.split('/').last
85
- @g.clone id
24
+ p [i, e]
86
25
  end
87
26
  end
88
27
  end
89
28
 
90
-
91
29
  if ENV['GISTY_DIR']
92
30
  begin
93
31
  @g = Gisty.new ENV['GISTY_DIR'], nil, nil, :ssl_ca => ENV['GISTY_SSL_CA'],
@@ -102,15 +40,8 @@ else
102
40
  exit
103
41
  end
104
42
 
105
- # load ext commands
106
- ext_path = File.join(ENV['GISTY_DIR'], 'commands', '*.rb')
107
- Dir.glob(ext_path).each do |i|
108
- begin
109
- load i
110
- rescue Exception => e
111
- p [i, e]
112
- end
113
- end
43
+ load_commnads Gisty::COMMAND_PATH
44
+ load_commnads File.join(ENV['GISTY_DIR'], 'commands')
114
45
 
115
46
  if ARGV.size == 0
116
47
  @cmds['help'].call []
@@ -122,4 +53,3 @@ else
122
53
  puts 'unknown commands.'
123
54
  end
124
55
  end
125
-
@@ -0,0 +1,6 @@
1
+ cmd :about, '', 'show about gisty' do
2
+ puts Gisty::AA
3
+ puts
4
+ puts 'version: ' + Gisty::VERSION
5
+ puts 'url: ' + Gisty::GISTY_URL
6
+ end
@@ -0,0 +1,23 @@
1
+ if /darwin/ === RUBY_PLATFORM
2
+ cmd :gyast, '', 'post screencapture' do
3
+ now = Time.now.to_i
4
+ file_jpg = "/tmp/#{now}.jpg"
5
+ system "screencapture -i -t jpg \"#{file_jpg}\""
6
+ unless File.exist? file_jpg
7
+ exit
8
+ end
9
+
10
+ begin
11
+ url = @g.create file_jpg
12
+ rescue Gisty::InvalidFileException => e
13
+ puts "Error: invalid file"
14
+ rescue Exception => e
15
+ puts "Error: #{e}"
16
+ else
17
+ id = url.split('/').last
18
+ @g.clone id
19
+ system "open https://gist.github.com/raw/#{id}/#{now}.jpg" if /darwin/ === RUBY_PLATFORM
20
+ end
21
+ File.delete file_jpg
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ cmd :help, '', 'show help' do
2
+ puts @help
3
+ end
@@ -0,0 +1,11 @@
1
+ cmd :list, '', 'show local list' do
2
+ list = @g.list
3
+ puts '- public gist -'
4
+ list[:public].each do |i|
5
+ puts "#{i[0]}: #{i[1].join(' ')}"
6
+ end
7
+ puts '- private gist -'
8
+ list[:private].each do |i|
9
+ puts "#{i[0]}: #{i[1].join(' ')}"
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ cmd :post, 'file1 file2 ...', 'post new gist' do |fs|
2
+ if fs.size > 0
3
+ begin
4
+ url = @g.create fs
5
+ rescue Gisty::InvalidFileException => e
6
+ puts "Error: invalid file"
7
+ rescue Exception => e
8
+ puts "Error: #{e}"
9
+ else
10
+ id = url.split('/').last
11
+ @g.clone id
12
+ system "open #{url}" if /darwin/ === RUBY_PLATFORM
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ cmd :private_post, 'file1 file2 ...', 'post new private gist' do |fs|
2
+ if fs.size > 0
3
+ begin
4
+ url = @g.create fs, :private => true
5
+ rescue Exception => e
6
+ puts "Error: #{e}"
7
+ else
8
+ system "open #{url}" if /darwin/ === RUBY_PLATFORM
9
+ id = url.split('/').last
10
+ @g.clone id
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ cmd :pull_all, '', 'pull all gist' do
2
+ @g.pull_all
3
+ puts '---'
4
+ puts 'pull_all finished.'
5
+ end
@@ -0,0 +1,5 @@
1
+ cmd :sync, '', 'sync remote gist (clone all remote gist)' do
2
+ @g.sync
3
+ puts '---'
4
+ puts 'sync finished.'
5
+ end
@@ -0,0 +1,5 @@
1
+ cmd :sync_delete, '', 'sync remote gist. delete local gist if remote gist was deleted' do
2
+ @g.sync true
3
+ puts '---'
4
+ puts 'sync finished.'
5
+ end
data/lib/gisty.rb CHANGED
@@ -7,9 +7,10 @@ require 'nokogiri'
7
7
  require 'net/https'
8
8
 
9
9
  class Gisty
10
- VERSION = '0.0.20'
10
+ VERSION = '0.0.21'
11
11
  GIST_URL = 'https://gist.github.com/'
12
12
  GISTY_URL = 'http://github.com/swdyh/gisty/tree/master'
13
+ COMMAND_PATH = Pathname.new(File.join(File.dirname(__FILE__), 'commands')).realpath.to_s
13
14
 
14
15
  class UnsetAuthInfoException < Exception
15
16
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gisty
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 20
10
- version: 0.0.20
9
+ - 21
10
+ version: 0.0.21
11
11
  platform: ruby
12
12
  authors:
13
13
  - swdyh
@@ -58,6 +58,15 @@ files:
58
58
  - test/fixtures/swdyh_page_4
59
59
  - test/gisty_test.rb
60
60
  - test/test_helper.rb
61
+ - lib/commands/about.rb
62
+ - lib/commands/gyast.rb
63
+ - lib/commands/help.rb
64
+ - lib/commands/list.rb
65
+ - lib/commands/post.rb
66
+ - lib/commands/private_post.rb
67
+ - lib/commands/pull_all.rb
68
+ - lib/commands/sync.rb
69
+ - lib/commands/sync_delete.rb
61
70
  - lib/gisty.rb
62
71
  has_rdoc: true
63
72
  homepage: http://github.com/swdyh/gisty/tree/master