davetron5000-gliffy 0.1.2 → 0.1.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.
data/bin/gliffy CHANGED
@@ -4,5 +4,24 @@ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
4
4
  $: << File.expand_path(File.dirname(__FILE__) + '/../ext')
5
5
 
6
6
  require 'gliffy/cli'
7
+ require 'rubygems'
8
+ require 'gli'
9
+ include GLI
7
10
 
8
- Gliffy::Command.execute(ARGV)
11
+ pre do |global_options,command,options,args|
12
+ if !Gliffy::CLIConfig.instance.load
13
+ raise "Problem loading config"
14
+ end
15
+ if command && command.name != :help
16
+ previous_token = Gliffy::CLIConfig.instance.config[:current_token]
17
+ Gliffy::Config.config.log_level = Logger::DEBUG if global_options[:v]
18
+ $gliffy = Gliffy::Handle.new(Gliffy::CLIConfig.instance.config[:username],previous_token)
19
+ end
20
+ end
21
+
22
+ desc 'be more verbose'
23
+ switch :v
24
+
25
+ require 'gliffy/commands'
26
+
27
+ GLI.run(ARGV)
data/lib/gliffy/cli.rb CHANGED
@@ -7,78 +7,6 @@ require 'logger'
7
7
  module Gliffy
8
8
  extend self
9
9
 
10
- # A command line option to the gliffy command line client
11
- class Command
12
-
13
- # Global flags
14
- GLOBAL_FLAGS = {
15
- '-v' => 'be more verbose (overrides config)',
16
- }
17
-
18
- # Global access to all configured commands
19
- def self.commands
20
- @@commands ||= {}
21
- end
22
-
23
- def self.aliases
24
- @@aliases ||= {}
25
- end
26
-
27
- # The name of the command
28
- attr_reader :name
29
- # a short description
30
- attr_reader :description
31
- # a usage statement
32
- attr_reader :usage
33
-
34
- # Create a new command
35
- #
36
- # [+name+] the name of the command (should be short, no spaces)
37
- # [+description+] short description of the command
38
- # [+offline+] true if this command doesn't require a connection to Gliffy
39
- # [+usage+] usage statement
40
- # [+block+] A block that represents the command itself. This block will take the gliffy handle and the args array as arguments *or* just the arguments if it is an "offline"
41
- # command
42
- def initialize(name,description,offline,usage,block)
43
- @name = name
44
- @description = description
45
- @block = block
46
- @offline = offline
47
- @usage = usage ? usage : ""
48
- end
49
-
50
- # Runs the command with the given arguments
51
- def run(args)
52
- if (@offline)
53
- @block.call(args)
54
- else
55
- previous_token = CLIConfig.instance.config[:current_token]
56
- handle = Gliffy::Handle.new(CLIConfig.instance.config[:username],previous_token)
57
- @block.call(handle,args)
58
- CLIConfig.instance.config[:current_token] = handle.current_token
59
- CLIConfig.instance.save
60
- end
61
- end
62
-
63
- # Executes the command line that was given
64
- def self.execute(argv)
65
- globals = Hash.new
66
- command = argv.shift
67
- while !command.nil? && (command =~ /^-/) && !argv.empty?
68
- globals[command] = true
69
- command = argv.shift
70
- end
71
- Gliffy::Config.config.log_level = Logger::DEBUG if globals['-v']
72
- cmd = Gliffy::Command.commands[command.to_sym]
73
- if cmd
74
- cmd.run argv
75
- else
76
- puts "Unknown command #{command}"
77
- Gliffy::Command.commands[:help].run []
78
- end
79
- end
80
- end
81
-
82
10
  # Represents the configuration for the command line client.
83
11
  # This is a singleton
84
12
  class CLIConfig
@@ -192,69 +120,9 @@ module Gliffy
192
120
 
193
121
  end
194
122
 
195
- # For defining commands, this specifies the description of the next command defined
196
- def desc(description)
197
- @next_desc = description
198
- end
199
-
200
- # For defining commands, this specifies if the next defined command is "offline"
201
- def offline(bool)
202
- @next_offline = bool
203
- end
204
-
205
- # For defining commands, specifies the usage statement of the next command
206
- def usage(usage='')
207
- @next_usage = usage
208
- end
209
-
210
- # defines a command. The only options supported is ":aliases" which is an array of aliases
211
- # for the command
212
- def command(name,options={},&block)
213
- Command.commands[name] = Command.new(name,@next_desc,@next_offline,@next_usage,block)
214
- if options[:aliases]
215
- options[:aliases].each() do |a|
216
- Command.commands[a] = Command.commands[name]
217
- Command.aliases[a] = true
218
- end
219
- end
220
- @next_usage = nil
221
- @next_offline = false
222
- @next_desc = nil
223
- end
224
-
225
- def parse_options(args)
226
- options = Hash.new
227
- return options if !args
228
- i = 0
229
- while i < args.length
230
- inc = 2
231
- if args[i] =~ /^-/
232
- arg = args[i].gsub(/^-/,'')
233
- if !args[i+1] || (args[i+1] =~ /^-/)
234
- inc = 1
235
- options[arg] = true
236
- else
237
- options[arg] = args[i+1]
238
- end
239
- else
240
- break
241
- end
242
- i += inc
243
- end
244
- i.times { args.shift }
245
- options
246
- end
247
-
248
123
  def format_date(date)
249
124
  date.strftime('%m/%d/%y %H:%M')
250
125
  end
251
126
 
252
127
  end
253
128
 
254
- include Gliffy
255
- require 'gliffy/commands/commands'
256
- if !CLIConfig.instance.load
257
- exit -1
258
- end
259
-
260
-
@@ -0,0 +1,6 @@
1
+ require 'gliffy/commands/list'
2
+ require 'gliffy/commands/delete'
3
+ require 'gliffy/commands/url'
4
+ require 'gliffy/commands/get'
5
+ require 'gliffy/commands/edit'
6
+ require 'gliffy/commands/new'
@@ -0,0 +1,10 @@
1
+ desc 'Delete a diagram'
2
+ arg_name 'diagram_id [diagram_id]*'
3
+ command [:delete,:del,:rm] do |c|
4
+ c.action do |global_options,options,args|
5
+ raise UnknownArgumentException("diagram id is required") if args.length == 0;
6
+ args.each do |diagram_id|
7
+ $gliffy.delete_diagram(diagram_id)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ desc 'Edit a diagram'
2
+ arg_name 'diagram_id'
3
+ command :edit do |c|
4
+
5
+ c.action do |global_options,options,args|
6
+
7
+ raise(UnknownArgumentException,'You must specify one diagram id') if args.length != 1
8
+
9
+ return_link = $gliffy.get_diagram_as_url(args[0])
10
+ link = $gliffy.get_edit_diagram_link(args[0],return_link,"Done")
11
+ if CLIConfig.instance.config[:open_url]
12
+ system(sprintf(CLIConfig.instance.config[:open_url],link.full_url))
13
+ else
14
+ puts "Nothing configured for #{:open_url.to_s} to open the url"
15
+ puts link.full_url
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,46 @@
1
+ desc 'Download a diagram as an image to a file'
2
+ arg_name 'diagram_id [diagram_id]*'
3
+ command :get do |c|
4
+
5
+ c.desc 'Get a specific version number'
6
+ c.arg_name 'version_number'
7
+ c.default_value nil
8
+ c.flag [:v,:version]
9
+
10
+ c.desc 'Specify the filename'
11
+ c.arg_name 'filename'
12
+ c.default_value nil
13
+ c.flag [:f,:filename]
14
+
15
+ c.desc 'Specify the image type (one of jpeg, jpg, png, svg, xml)'
16
+ c.arg_name 'type'
17
+ c.default_value 'jpg'
18
+ c.flag [:t,:type,:"image-type"]
19
+
20
+ c.action do |global_options,options,args|
21
+
22
+ raise(UnknownArgumentException,'You must specify a diagram id') if args.length == 0
23
+ raise(MissingArgumentException,'You may not specify a filename when getting multiple diagrams') if args.length > 1 and options[:f]
24
+ args.each do |diagram_id|
25
+
26
+ version_number = options[:v]
27
+ filename = options[:f]
28
+ type = options[:t].to_sym
29
+ if !filename
30
+ dir = options['d'] || '.'
31
+ metadata = $gliffy.get_diagram_metadata(diagram_id)
32
+ filename = metadata.name.gsub(/[\s\/\-\+\$]/,'_')
33
+ if version_number
34
+ filename = "#{dir}/#{filename}_v#{version_number}.#{type.to_s}"
35
+ else
36
+ filename = "#{dir}/#{filename}.#{type.to_s}"
37
+ end
38
+ end
39
+
40
+ get_options = { :mime_type => type, :file => filename }
41
+ get_options[:version] = version_number if version_number
42
+ $gliffy.get_diagram_as_image(diagram_id,get_options)
43
+ puts filename
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ desc 'List all diagrams in the account'
2
+ command [:list,:ls] do |c|
3
+
4
+ c.desc 'List long form'
5
+ c.switch :l
6
+
7
+ c.action do |global_options,options,args|
8
+ diagrams = $gliffy.get_diagrams
9
+ if options[:l]
10
+ max = diagrams.inject(0) { |max,diagram| diagram.name.length > max ? diagram.name.length : max }
11
+ diagrams.sort.each do |diagram|
12
+ printf "%8d %s %-#{max}s %-3d %s %s %s\n",
13
+ diagram.id,
14
+ diagram.is_public? ? "P" : "-",
15
+ diagram.name,
16
+ diagram.num_versions,
17
+ format_date(diagram.create_date),
18
+ format_date(diagram.mod_date),
19
+ diagram.owner_username
20
+ end
21
+ else
22
+ printf_string = "%d %s\n"
23
+ diagrams.sort.each { |diagram| printf printf_string,diagram.id,diagram.name }
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,25 @@
1
+ desc 'Create a new diagram'
2
+ arg_name 'new_diagram_name'
3
+ command [:new,:create] do |c|
4
+ c.desc 'use the given diagram_id as a template'
5
+ c.default_value nil
6
+ c.flag [:t,:template]
7
+
8
+ c.desc 'don\'t edit the new diagram'
9
+ c.switch [:n,:"no-edit"]
10
+
11
+ c.action do |global_options,options,args|
12
+
13
+ raise(UnknownArgumentException,'You must specify the diagram name') if args.length != 1
14
+
15
+ template_id = options[:t]
16
+
17
+ diagram = $gliffy.create_diagram(args[0],template_id)
18
+ if options[:n]
19
+ puts "Diagram #{diagram.name} created with id #{diagram.id}"
20
+ else
21
+ GLI.run(['edit',diagram.id.to_s])
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,21 @@
1
+ desc 'Get the URL for a diagram as an image image'
2
+ arg_name 'diagram_id'
3
+ command :url do |c|
4
+ c.desc 'Open URL with configured :open_url command'
5
+ c.switch [:o,:open]
6
+ c.action do |global_options,options,args|
7
+ raise UnknownArgumentException,"diagram id is required" if args.length == 0
8
+ raise UnknownArgumentException,"Only one diagram id is supported" if args.length > 1
9
+ url = $gliffy.get_diagram_as_url(args[0])
10
+ if options[:o]
11
+ if CLIConfig.instance.config[:open_image]
12
+ system(sprintf(CLIConfig.instance.config[:open_image],url))
13
+ else
14
+ puts "Nothing configured for #{:open_image.to_s} to open the image"
15
+ puts url
16
+ end
17
+ else
18
+ puts url
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: davetron5000-gliffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Copeland
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-11 00:00:00 -08:00
12
+ date: 2009-02-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -21,6 +21,15 @@ dependencies:
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.5.1
23
23
  version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: davetron5000-gli
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.1.4
32
+ version:
24
33
  description:
25
34
  email: davidcopeland@naildrivin5.com
26
35
  executables:
@@ -31,9 +40,16 @@ extra_rdoc_files:
31
40
  - README.rdoc
32
41
  files:
33
42
  - ext/array_has_response.rb
43
+ - bin/gliffy
34
44
  - lib/gliffy/account.rb
35
45
  - lib/gliffy/cli.rb
36
- - lib/gliffy/commands/commands.rb
46
+ - lib/gliffy/commands/delete.rb
47
+ - lib/gliffy/commands/edit.rb
48
+ - lib/gliffy/commands/get.rb
49
+ - lib/gliffy/commands/list.rb
50
+ - lib/gliffy/commands/new.rb
51
+ - lib/gliffy/commands/url.rb
52
+ - lib/gliffy/commands.rb
37
53
  - lib/gliffy/config.rb
38
54
  - lib/gliffy/diagram.rb
39
55
  - lib/gliffy/folder.rb
@@ -43,7 +59,6 @@ files:
43
59
  - lib/gliffy/url.rb
44
60
  - lib/gliffy/user.rb
45
61
  - lib/gliffy.rb
46
- - bin/gliffy
47
62
  - README.rdoc
48
63
  has_rdoc: true
49
64
  homepage: http://davetron5000.github.com/gliffy
@@ -1,152 +0,0 @@
1
- desc 'List all diagrams in the account'
2
- usage <<eos
3
- [-l]
4
-
5
- -l - show all information
6
- eos
7
- command :list, :aliases => [:ls] do |gliffy,args|
8
- diagrams = gliffy.get_diagrams
9
- options = parse_options(args)
10
- if options['l']
11
- max = diagrams.inject(0) { |max,diagram| diagram.name.length > max ? diagram.name.length : max }
12
- diagrams.sort.each do |diagram|
13
- printf "%8d %s %-#{max}s %-3d %s %s %s\n",
14
- diagram.id,
15
- diagram.is_public? ? "P" : "-",
16
- diagram.name,
17
- diagram.num_versions,
18
- format_date(diagram.create_date),
19
- format_date(diagram.mod_date),
20
- diagram.owner_username
21
- end
22
- else
23
- printf_string = "%d %s\n"
24
- diagrams.sort.each { |diagram| printf printf_string,diagram.id,diagram.name }
25
- end
26
- end
27
-
28
- desc 'Delete a diagram'
29
- usage 'diagram_id'
30
- command :delete, :aliases => [:del,:rm] do |gliffy,args|
31
- gliffy.delete_diagram(args[0])
32
- end
33
-
34
- desc 'Get the URL for an image'
35
- usage <<eos
36
- [-o] diagram_id
37
-
38
- -o - open diagram's URL with configured :open_url command
39
- eos
40
- command :url do |gliffy,args|
41
- open = args[0] == '-o'
42
- args.shift if open
43
- url = gliffy.get_diagram_as_url(args[0])
44
- if open
45
- if CLIConfig.instance.config[:open_image]
46
- system(sprintf(CLIConfig.instance.config[:open_image],url))
47
- else
48
- puts "Nothing configured for #{:open_image.to_s} to open the image"
49
- puts url
50
- end
51
- else
52
- puts url
53
- end
54
- end
55
-
56
- desc 'Download a diagram as an image to a file'
57
- usage <<eos
58
- [-v version_num] [-f filename] [-d download_dir] [-t image_type] diagram_id
59
-
60
- image_type can be :jpeg, :jpg, :png, :svg, or :xml
61
- if no filename specified, uses the diagram's name
62
- if -d and -f are specified, -d is ignored
63
- eos
64
- command :get do |gliffy,args|
65
-
66
- options = parse_options(args)
67
- diagram_id = args.shift
68
-
69
- version_number = options['v'].to_i if options['v']
70
- filename = options['f'] if options['f']
71
- type = options['t'].to_sym if options['t']
72
- type = :jpg if !type
73
- if !filename
74
- dir = options['d'] || '.'
75
- metadata = gliffy.get_diagram_metadata(diagram_id)
76
- filename = metadata.name.gsub(/[\s\/\-\+\$]/,'_')
77
- if version_number
78
- filename = "#{dir}/#{filename}_v#{version_number}.#{type.to_s}"
79
- else
80
- filename = "#{dir}/#{filename}.#{type.to_s}"
81
- end
82
- end
83
-
84
- get_options = { :mime_type => type, :file => filename }
85
- get_options[:version] = version_number if version_number
86
- gliffy.get_diagram_as_image(diagram_id,get_options)
87
- puts filename
88
- end
89
-
90
- desc 'Edit a diagram'
91
- usage 'diagram_id'
92
- command :edit do |gliffy,args|
93
- return_link = gliffy.get_diagram_as_url(args[0])
94
- link = gliffy.get_edit_diagram_link(args[0],return_link,"Done")
95
- if CLIConfig.instance.config[:open_url]
96
- system(sprintf(CLIConfig.instance.config[:open_url],link.full_url))
97
- else
98
- puts "Nothing configured for #{:open_url.to_s} to open the url"
99
- puts link.full_url
100
- end
101
- end
102
-
103
- desc 'Create a new diagram'
104
- usage <<eos
105
- [-t template_id] diagram_name
106
-
107
- -t specify the id of a diagram to server as the initial revision
108
- eos
109
- command :new do |gliffy,args|
110
- options = parse_options(args)
111
- name = args.shift
112
- template_id = options['t']
113
-
114
- diagram = gliffy.create_diagram(name,template_id)
115
- Gliffy::Command.commands[:edit].run [diagram.id]
116
- end
117
-
118
- desc 'Show commands'
119
- offline true
120
- usage 'command'
121
- command :help do |args|
122
- if args[0]
123
- command = Command.commands[args[0].to_sym]
124
- if command
125
- printf "%s - %s\n",args[0],command.description
126
- printf "usage: %s %s\n",args[0],command.usage
127
- else
128
- puts "No such command #{args[0]}"
129
- end
130
- else
131
- command_string = " %-6s %s %s\n"
132
- puts 'usage: gliffy [global_options] command [command_options]'
133
- puts 'global_options:'
134
- Command::GLOBAL_FLAGS.keys.sort.each do |flag|
135
- printf command_string,flag,Command::GLOBAL_FLAGS[flag],''
136
- end
137
- puts
138
- puts 'command:'
139
- command_names = Command.commands.keys.sort { |a,b| a.to_s <=> b.to_s }
140
- command_names.each() do |name|
141
- command = Command.commands[name]
142
- if !Command.aliases[name]
143
- aliases = Array.new
144
- Command.aliases.keys.each() do |a|
145
- aliases << a if Command.commands[a] == command
146
- end
147
- alias_string = '(also: ' + aliases.join(',') + ')' if aliases.length > 0
148
- printf command_string,name.to_s, command.description,alias_string
149
- end
150
- end
151
- end
152
- end