Sha256: bbbe26ba680fe66fffaf53fc4fe9e08e0d8e38f430f10180e9425fbc4c3e50ef

Contents?: true

Size: 1.76 KB

Versions: 5

Compression:

Stored size: 1.76 KB

Contents

#!/usr/bin/env ruby

require "sfn"

print "Generating command and configuration page..."

klasses = Sfn::Config.constants.sort.map do |const|
  klass = Sfn::Config.const_get(const)
  klass if klass.is_a?(Class) && klass.respond_to?(:attributes)
end.compact

file = File.open(File.join(File.dirname(__FILE__), "..", "docs", "command-config.md"), "w")

file.puts <<-EOS
---
title: "Configuration"
weight: 6
anchors:
EOS

klasses.each do |klass|
  file.puts "  - title: \"#{klass.name.split("::").last} Command\""
  file.puts "    url: \"##{klass.name.split("::").last.downcase}-command\""
end
file.puts "---"
file.puts <<-EOS

# Command configurations

This lists commands and the options which the commands accept. It also
includes the valid types which the options will accept. Options can be
set with the `.sfn` configuration file to apply default values which
can be overridden on the CLI. Options defined within the `.sfn` configuration
file are the option name with `-` characters replaced with `_`.

For example, the option `--apply-mapping` can be defined in the `.sfn`
configuration file as:

~~~ruby
Configuration.new do
  apply_mapping true
end
~~~

EOS

klasses.each do |klass|
  file.puts "## #{klass.name.split("::").last} Command"
  file.puts
  file.puts "~~~"
  file.puts "$ sfn #{klass.name.split("::").last.downcase}"
  file.puts "~~~"
  file.puts "\n"
  file.puts "| Option | Attribute | Value"
  file.puts "|--------|-----------|------"
  klass.attributes.sort_by(&:first).map do |name, value|
    file.puts "| `--#{name.to_s.tr("_", "-")}` | Description | #{value[:description]} |"
    file.puts "| | Valid | `#{[value[:type]].flatten.compact.join("`, `")}` |"
    file.puts "| | Default | #{value[:default].inspect unless value[:default].nil?}|\n"
  end
  file.puts
end

puts "done"

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sfn-3.1.8 bin/command-config-generator
sfn-3.1.6 bin/command-config-generator
sfn-3.1.4 bin/command-config-generator
sfn-3.1.2 bin/command-config-generator
sfn-3.1.0 bin/command-config-generator