michaelmior /
nose-cli
| 1 | # frozen_string_literal: true |
||
| 2 | |||
| 3 | require 'rspec/core/rake_task' |
||
| 4 | require 'yard' |
||
| 5 | require 'yard-thor' |
||
| 6 | |||
| 7 | # XXX: Patch OpenStruct for yard-thor |
||
| 8 | class OpenStruct |
||
| 9 | def delete(name) |
||
| 10 | delete_field name |
||
| 11 | end |
||
| 12 | end |
||
| 13 | |||
| 14 | RSpec::Core::RakeTask.new(:spec) |
||
| 15 | YARD::Rake::YardocTask.new(:doc) |
||
| 16 | task :completions do |
||
| 17 | require 'nose' |
||
| 18 | require_relative './lib/nose_cli' |
||
| 19 | |||
| 20 | commands = NoSE::CLI::NoSECLI.all_commands.to_a.sort_by(&:first) |
||
| 21 | |||
| 22 | tmpl = File.read File.join(File.dirname(__FILE__), |
||
| 23 | 'templates/completions.erb') |
||
| 24 | ns = OpenStruct.new commands: commands |
||
| 25 | puts ERB.new(tmpl, nil, '>').result(ns.instance_eval { binding }) |
||
| 26 | end |
||
| 27 | |||
| 28 | task :man do |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 29 | require 'erb' |
||
| 30 | require 'fakefs/safe' |
||
| 31 | require 'fileutils' |
||
| 32 | require 'ronn' |
||
| 33 | require_relative './lib/nose/cli' |
||
| 34 | |||
| 35 | # Write the generated Markdown to a fake file then process with ronn |
||
| 36 | def output_man(markdown, name) |
||
| 37 | FakeFS.activate! |
||
| 38 | |||
| 39 | path = "#{name}.md" |
||
| 40 | File.open(path, 'w') { |f| f.write markdown } |
||
| 41 | doc = Ronn::Document.new(path) |
||
| 42 | roff = doc.convert('roff') |
||
| 43 | |||
| 44 | FakeFS.deactivate! |
||
| 45 | |||
| 46 | # Output the generated man page |
||
| 47 | FileUtils.mkdir_p 'man' |
||
| 48 | File.open("man/#{name}.1", 'w') { |f| f.write roff } |
||
| 49 | end |
||
| 50 | |||
| 51 | # Generate the man page for the main command |
||
| 52 | ns = OpenStruct.new commands: NoSE::CLI::NoSECLI.commands, |
||
| 53 | options: NoSE::CLI::NoSECLI.class_options |
||
| 54 | tmpl = File.read File.join(File.dirname(__FILE__), 'templates/man.erb') |
||
| 55 | out = ERB.new(tmpl, nil, '>').result(ns.instance_eval { binding }) |
||
| 56 | output_man out, 'nose' |
||
| 57 | |||
| 58 | # Generate man pages for each subcommand |
||
| 59 | NoSE::CLI::NoSECLI.commands.each_value do |command| |
||
| 60 | ns = OpenStruct.new command: command |
||
| 61 | tmpl = File.read File.join(File.dirname(__FILE__), 'templates/subman.erb') |
||
| 62 | out = ERB.new(tmpl, nil, '>').result(ns.instance_eval { binding }) |
||
| 63 | |||
| 64 | output_man out, "nose-#{command.name}" |
||
| 65 | end |
||
| 66 | end |
||
| 67 | |||
| 68 | task default: :spec |
||
| 69 |