#!/usr/bin/env ruby STDOUT.sync = true $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') if RUBY_VERSION < '1.9' require 'rubygems' end require 'commander/import' require 'hyla' require 'hyla/project' program :version, Hyla::VERSION program :description, Hyla::DESCRIPTION default_command :default def add_build_options(c) c.option '-c','--config CONFIG_FILE', String, 'Custom configuration file' c.option '-V','--verbose', 'Print verbose output.' end def add_common_options(c) c.option '-s', '--source [DIR]', String, 'Source directory (defaults to ./)' c.option '-d', '--destination [DIR]', String, 'Destination directory (defaults to ./generated_content)' end # # Creates a new Hyla project using a template or blank to the PATH specified # command :new do |c| c.syntax = 'hyla new [options]' c.description = 'Creates a new Hyla project using a template or blank to the PATH specified' c.option '-f','--force', 'Force creation even if PATH already exists' c.option '-b','--blank', 'Creates project but with empty files' c.option '--t','--template_type [TEMPLATE_TYPE]', String, 'Template Type to be used (documentation, book, training, training-exercises, blog, web, ...)' add_common_options(c) add_build_options(c) c.action do |args, options| config = Hyla::Configuration.parse(options.__hash__) Hyla::Commands::New.process(args, config) end end # # Creates a new file from an artefact within an existing project # command :add do |c| c.syntax = 'hyla add [options]' c.description = 'Add a new file using one of the different asciidoc samples/artefacts' c.option '-a', '--artefact_type [ARTEFACT_TYPE]', String, 'Artefact Type : article, audio, video, blog entry ...' c.option '--t', '--type [TYPE]', String, 'Type : asciidoc, slideshow' add_common_options(c) add_build_options(c) c.action do |args, options| config = Hyla::Configuration.parse(options.__hash__) Hyla::Commands::Add.process(args, config) end end # # Generate from asciidoc files content according to rendering/transformation requested # command :generate do |c| c.syntax = 'hyla generate [OPTIONS]' c.description = 'Generate content from asciidoc files (Table Of Content, modules, ...) to HTML, Slideshow' c.option '-b', '--backend [BACKEND]', String, 'Backend to be used : HTML5, deckjs, revealjs, ...' c.option '-f', '--file [HTML FILE]', String, 'HTML File name' c.option '-p', '--project_name [PROJECT_NAME]', String, 'Project Name' c.option '-r', '--rendering [RENDERING]', String, 'Code of the rendering : adoc2html, index2html, html2pdf, toc2adoc' c.option '--t', '--toc [PATH]', String, 'File Path of the asciidoc file containing the Table of Content' c.option '-y', '--style [STYLE]', String, 'Stylesheet theme to be applied : asciidoctor, liberation, github, colony, foundation, ...' c.option '-a', '--attributes [KEY=VALUE,KEY=VALUE]', String, 'Asciidoctor attributes' c.option '-o','--cover_image [PNG FILE NAME]', String, 'Name of the cover png image file generated' c.option '-n','--course_name [COURSE NAME]', String, 'Name of the course' c.option '-l','--cover_file [HTML FILE NAME]', String, 'Name of the cover html image file generated' c.option '-m','--module_name [MODULE NAME]', String, 'Name of the module' c.option '-i','--image_path [BACKGROUND IMAGE]', String, 'Location of the file used as background' add_common_options(c) add_build_options(c) c.action do |args, options| config = Hyla::Configuration.parse(options.__hash__) Hyla::Commands::Generate.process(args, config) end end # Watch command :watch do |c| c.syntax = 'hyla watch [options]' c.description = 'Watch directories for any change, add or file deleted and render document (HTML5)' add_common_options(c) add_build_options(c) c.action do |args, options| # TODO Find if it is possible to watch files, generate HTML content - asciidoctor, expose content using HTTPServer and expose WebSocket - LiveReload # as they are started in 2 different threads, this is not possible with existing code # Hyla::Commands::Serve.process(args,options.__hash__) config = Hyla::Configuration.parse(options.__hash__) Hyla::Commands::Watch.process(args, config) end end # Serve your content locally command :serve do |c| c.syntax = 'hyla serve [options]' c.description = 'Serve your content locally' c.option '-out_dir DIR', String, 'Output directory where content must be generated' c.option '-B', '--detach', 'Run the server in the background (detach)' c.option '-P', '--port [PORT]', 'Port to listen on' c.option '-H', '--host [HOST]', 'Host to bind to' c.option '-b', '--baseurl [URL]', 'Base URL' add_common_options(c) add_build_options(c) c.action do |args, options| options.default :serving => true config = Hyla::Configuration.parse(options.__hash__) Hyla::Commands::Serve.process(args, config) end end alias_command :server, :serve # # Send as email attachment HTML file # command :sendmail do |c| c.syntax = 'hyla sendmail [options]' c.description = 'Send as HTML Attachment an email to the SMTP Server defined' c.option '-f', '--file [File]', String, 'File to be attached' c.option '-l', '--location [PATH]', String, 'Directory containing file to be attached' c.option '-a', '--attachment [boolean]', 'Attach to the email the HTML generated' c.option '-e', '--email_attributes [KEY=VALUE,KEY=VALUE]', String, 'Email attributes used to configure smtp server, port number, user password, authentication mode, sender, recipient, subject' add_common_options(c) add_build_options(c) c.action do |args, options| options.default :attachment => false config = Hyla::Configuration.parse(options.__hash__) Hyla::Commands::Sendmail.process(args, config) end end # NOT YET AVAILABLE =begin # TODO NOT FINALISED # Reload command :reload do |c| c.syntax = 'hyla reload [options]' c.description = 'Reload HTML files generated within the browser - Livereload using WebSocket Server' c.action do |args, options| Hyla::Commands::Reload.process(options.__hash__) end end # Command generating output format from asciidoc files command :build do |c| c.syntax = 'hyla build [options]' c.description = 'Generating output content (HTML, PDF, ManPages, ...) from asciidoc(tor) files' c.option '--some-switch', 'Some switch that does something' c.action do |args, options| Hyla::Commands::Build.process(args, options.__hash__) end end command :publish do |c| c.syntax = 'hyla publish [options]' c.description = '' c.example 'description', 'command example' c.option '--some-switch', 'Some switch that does something' c.action do |args, options| Hyla::Commands::Publish.process(args, options.__hash__) end end =end