Class Webgen::UseCommand
In: lib/webgen/cli.rb
Parent: CmdParse::Command
RuntimeError PluginParamNotFound PluginNotFound ConfigurationFileInvalid CmdParse::CommandParser CommandParser DirectoryInfo GalleryStyle WebSiteStyle WebSiteTemplate SipttraStyle Test::Unit::TestCase TestCase PluginTestCase TagTestCase CmdParse::Command ShowCommand CheckCommand UseCommand CreateCommand TSort DependencyHash Hash Comparable Language DEFAULT_WRAPPER_MODULE WebSite ::Logger Logger Logger Qt::MainWindow MainWindow Qt::Dialog NewWebsiteDialog Qt::TextEdit LogWidget ::Rake::TaskLib WebgenTask ConfigurationFile Website PluginManager PluginLoader PluginParamValueNotFound Dummy Color CliUtils PluginDefs lib/webgen/languages.rb lib/webgen/website.rb lib/webgen/gui/common.rb lib/webgen/plugin.rb lib/webgen/test.rb lib/webgen/cli.rb ClassMethods PluginDefs LanguageManager lib/webgen/gui/new_website_dlg.rb lib/webgen/gui/main.rb GUI lib/webgen/rake/webgentask.rb Rake Webgen dot/m_60_0.png

Methods

ask_overwrite   new  

Public Class methods

[Source]

     # File lib/webgen/cli.rb, line 135
135:     def initialize( cmdparser )
136:       super( 'use', true )
137:       self.short_desc = "Changes the used website or gallery styles"
138: 
139:       @force = false
140:       self.options = CmdParse::OptionParserWrapper.new do |opts|
141:         opts.separator "Options:"
142:         opts.on( '-f', '--[no-]force', 'If specified, existing files are overwritten without asking.' ) {|@force|}
143:       end
144: 
145:       # Use website style command.
146:       useWebsiteStyle = CmdParse::Command.new( 'website_style', false )
147:       useWebsiteStyle.short_desc = "Changes the used website style"
148:       useWebsiteStyle.description =
149:         CliUtils.format("\nCopies the style files for the website style STYLE to the website " +
150:                         "directory defined by the global directory option, overwritting existing " +
151:                         "files. If the global verbosity level is set to 0 or 1, the copied files are listed.")
152:       useWebsiteStyle.options = CmdParse::OptionParserWrapper.new do |opts|
153:         opts.separator "Available styles:"
154:         opts.separator ""
155:         Webgen::WebSiteStyle.entries.sort.each {|name, entry| CliUtils.dirinfo_output( opts, name, entry ) }
156:       end
157:       def useWebsiteStyle.usage
158:         "Usage: #{commandparser.program_name} [global options] use website_style STYLE"
159:       end
160:       useWebsiteStyle.set_execution_block do |args|
161:         if args.length == 0
162:           raise OptionParser::MissingArgument.new( 'STYLE' )
163:         else
164:           if @force || ask_overwrite
165:             files = Webgen::WebSite.use_website_style( cmdparser.directory, args[0] )
166:             if (0..1) === cmdparser.verbosity
167:               puts "The following files were created or overwritten:"
168:               puts files.collect {|f| "- " + f }.join("\n")
169:             end
170:           end
171:         end
172:       end
173:       self.add_command( useWebsiteStyle )
174: 
175:       # Use gallery style command.
176:       useGalleryStyle = CmdParse::Command.new( 'gallery_style', false )
177:       useGalleryStyle.short_desc = "Changes the used gallery style"
178:       useGalleryStyle.description =
179:         CliUtils.format("\nCopies the gallery templates for the gallery style STYLE to the website " +
180:                         "directory defined by the global directory option, overwritting existing files. " +
181:                         "If the global verbosity level is set to 0 or 1, the copied files are listed.")
182:       useGalleryStyle.options = CmdParse::OptionParserWrapper.new do |opts|
183:         opts.separator "Available styles:"
184:         opts.separator ""
185:         Webgen::GalleryStyle.entries.sort.each {|name, entry| CliUtils.dirinfo_output( opts, name, entry ) }
186:       end
187:       def useGalleryStyle.usage
188:         "Usage: #{commandparser.program_name} [global options] use gallery_style STYLE"
189:       end
190:       useGalleryStyle.set_execution_block do |args|
191:         if args.length == 0
192:           raise OptionParser::MissingArgument.new( 'STYLE' )
193:         else
194:           if @force || ask_overwrite
195:             files = Webgen::WebSite.use_gallery_style( cmdparser.directory, args[0] )
196:             if (0..1) === cmdparser.verbosity
197:               puts "The following files were created or overwritten:"
198:               puts files.collect {|f| "- " + f }.join("\n")
199:             end
200:           end
201:         end
202:       end
203:       self.add_command( useGalleryStyle )
204: 
205:       # Use sipttra style command.
206:       useSipttraStyle = CmdParse::Command.new( 'sipttra_style', false )
207:       useSipttraStyle.short_desc = "Changes the used sipttra style"
208:       useSipttraStyle.description =
209:         CliUtils.format("\nCopies the sipttra styles files for the sipttra style STYLE to the website " +
210:                         "directory defined by the global directory option, overwritting existing files. " +
211:                         "If the global verbosity level is set to 0 or 1, the copied files are listed.")
212:       useSipttraStyle.options = CmdParse::OptionParserWrapper.new do |opts|
213:         opts.separator "Available styles:"
214:         opts.separator ""
215:         Webgen::SipttraStyle.entries.sort.each {|name, entry| CliUtils.dirinfo_output( opts, name, entry ) }
216:       end
217:       def useSipttraStyle.usage
218:         "Usage: #{commandparser.program_name} [global options] use sipttra_style STYLE"
219:       end
220:       useSipttraStyle.set_execution_block do |args|
221:         if args.length == 0
222:           raise OptionParser::MissingArgument.new( 'STYLE' )
223:         else
224:           if @force || ask_overwrite
225:             files = Webgen::WebSite.use_sipttra_style( cmdparser.directory, args[0] )
226:             if (0..1) === cmdparser.verbosity
227:               puts "The following files were created or overwritten:"
228:               puts files.collect {|f| "- " + f }.join("\n")
229:             end
230:           end
231:         end
232:       end
233:       self.add_command( useSipttraStyle )
234:     end

Private Instance methods

[Source]

     # File lib/webgen/cli.rb, line 240
240:     def    ask_overwriteask_overwriteask_overwriteask_overwrite
241:       printf "Existing files may get overwritten, procede (yes/no)? : "
242:       $stdin.gets =~ /y|yes/
243:     end

[Validate]