Skip to content

Commit

Permalink
update cli; use gli cont.
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Jun 17, 2013
1 parent b0d8445 commit 5f19d18
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 56 deletions.
1 change: 1 addition & 0 deletions Manifest.txt
Expand Up @@ -12,6 +12,7 @@ lib/slideshow/cli/commands/gen_templates.rb
lib/slideshow/cli/commands/list.rb
lib/slideshow/cli/commands/plugins.rb
lib/slideshow/cli/commands/quick.rb
lib/slideshow/cli/main.rb
lib/slideshow/cli/opts.rb
lib/slideshow/cli/runner.rb
lib/slideshow/config.rb
Expand Down
1 change: 1 addition & 0 deletions bin/slideshow
Expand Up @@ -3,3 +3,4 @@
require 'slideshow'

Slideshow.main

8 changes: 7 additions & 1 deletion lib/slideshow.rb
Expand Up @@ -94,7 +94,7 @@ def self.generator
end


def self.main
def self.main_old

# allow env variable to set RUBYOPT-style default command line options
# e.g. -o slides -t <your_template_manifest_here>
Expand All @@ -107,6 +107,12 @@ def self.main
Runner.new.run(args)
end

def self.main
require 'slideshow/cli/main'
## Runner.new.run(ARGV) - old code
end


end # module Slideshow

# load built-in (optional) helpers/plugins/engines
Expand Down
111 changes: 56 additions & 55 deletions lib/slideshow/cli/main.rb
@@ -1,120 +1,121 @@
# encoding: utf-8


LogUtils::Logger.root.level = :info # set logging level to info


require 'gli'

include GLI::App

program_desc 'Slide Show (S9) - a free web alternative to PowerPoint and Keynote'

##
## -t/--template ??
## -c/--config-dir ??
version Slideshow::VERSION


## some setup code

LogUtils::Logger.root.level = :info # set logging level to info

opts = Slideshow::Opts.new



## "global" options (switches/flags)

desc "(Debug) Show debug messages" # add --debug as alias? - add -w why? why not?
switch [:verbose] # NB: using -w as switch not -v (-v is used for version) - why w? who else is using it? ruby interpreter? check

desc "Only show warnings, errors and fatal messages"
switch [:q, :quiet]


global_option '-i', '--include PATH', String, "Data path (default is #{myopts.data_path})"
global_option '-d', '--dbpath PATH', String, "Database path (default is #{myopts.db_path})"
global_option '-n', '--dbname NAME', String, "Database name (datault is #{myopts.db_name})"
desc "Configuration Path (default is #{opts.config_path})"
arg_name 'PATH'
flag [:c, :config]

global_option '-q', '--quiet', "Only show warnings, errors and fatal messages"
### todo/fix: just want --debug/--verbose flag (no single letter option wanted) - fix
global_option '-w', '--verbose', "Show debug messages"
desc "Template Manifest (default is #{opts.manifest})"
arg_name 'MANIFEST'
flag [:t, :template]



desc 'Build slideshow'
command [:b,:build] do |c|

c.desc 'Verbose/Debug'
c.switch :verbose
c.desc 'Set Header Level to 1 (default)'
c.switch [:h1] # todo: add :1 if it works e.g. -1 why? why not??

c.desc 'Set Header Level to 2'
c.switch [:h2]

c.desc 'Use only !SLIDE for slide breaks (Showoff Compatible)'
c.switch [:slide]

# cmd.on( '--h1', 'Set Header Level to 1 (default)' ) { opts.header_level = 1 }
# cmd.on( '--h2', 'Set Header Level to 2' ) { opts.header_level = 2 }
#
# cmd.on( '--slide', 'Use only !SLIDE for slide breaks (Showoff Compatible)' ) do
# opts.slide = true
# end
#
# cmd.on( '--takahashi', 'Allow // for slide breaks' ) do
# opts.takahashi = true
# end
c.desc 'Allow // for slide breaks'
c.switch [:takahashi]


c.desc 'Config Folder'
c.default_value "tbd" # use opts.template ??
c.flag [:c,:config]

c.desc 'Output Folder'
c.default_value "tbd" # use opts.template ??
c.desc "Output Path (default is #{opts.output_path})"
c.arg_name 'PATH'
c.flag [:o,:output]

c.desc 'Template'
c.default_value "tbd" # use opts.template ??
c.flag [:t,:template]

c.action do |global_options,options,args|

load_plugins # check for optional plugins/extension in ./lib folder

args.each do |arg|
files = find_files( arg )
files.each do |file|
### fix/todo: reset/clean headers
Gen.new( opts, config, headers ).create_slideshow( file )
end
end
puts "hello from build command"

end
end


desc 'List all installed template packs'
command [:l,:ls,:list] do |c|
c.desc 'List all installed template packs'

c.action do |global_options,options,args|
List.new( opts, config ).run ### todo: remove opts (merge access into config)

puts "hello from list command"

end
end


desc 'Install (fetch) template pack'
command [:f,:fetch,:i,:install] do |c|
c.desc 'Install/fetch template pack'

c.action do |global_options,options,args|

Fetch.new( opts, config ).run ### todo: remove opts
puts "hello from install/fetch command"

end
end


command [:q,:quick,:n,:new] do |c| # quick - use g,gen,generate? too for templates?
c.action do |global_options,options,args|

## if opts.quick?
Quick.new( opts, config ).run ### todo: remove opts
c.action do |global_options,options,args|

## if opts.generate?
GenTemplates.new( opts, config ).run ### todo: remove opts
puts "hello from quick/new command"

end
end


command [:a,:about,:info] do |c|
c.action do
# do something here
puts "hello from about command"
end
end


command [:p,:plugin,:plugins] do |c|
c.action do
# if opts.plugins?
Plugins.new( opts, config ).run ### todo: remove opts (merge access into config)
puts "hello from plugin command"
end
end

command :test do |c|
c.action do
puts "hello from test command"
end
end


exit run(ARGV)

0 comments on commit 5f19d18

Please sign in to comment.