Commit afeb608e authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add documentation for the command line interface

parent 4002c4aa
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ int main(int argc, const char** argv) {
  flag_parser.defineSwitch("debug", &flag_debug);

  bool flag_font_defaults = true;
  flag_parser.defineSwitch("font-defaults", &flag_font_defaults);
  flag_parser.defineBool("font-defaults", &flag_font_defaults);

  std::vector<std::string> flag_font_load;
  flag_parser.defineStringV("font-load", &flag_font_load);
@@ -77,13 +77,20 @@ int main(int argc, const char** argv) {
  if (flag_help) {
    std::cerr <<
        "Usage: $ fviz [OPTIONS]\n"
        "  --in <path>               Path to the input file\n"
        "  --out <path>              Path to the output file\n"
        "  --outfmt <format>         Output format. If no format is given, it is inferred from the\n"
        "                            filename. Valid values: 'png', 'svg'\n"
        "  --font-defaults <bool>    Enable or disable default font loading. Default is enabled.\n"
        "                            Valid values: 'on' and 'off'\n"
        "  --font-load <path>        Add a font file to the default font list\n"
        "  --debug                   Run in debug mode\n"
        "  --help                    Display this help text and exit\n"
        "  --version                 Display the version of this binary and exit\n"
        "\n"
        "Commands:\n";
        "Examples:\n"
        "  $ fviz --in my_chart.fvz --out my_chart.svg\n";


    std::cerr << "\nSee 'fviz help <command>' for information about a specific subcommand.\n";
    return 0;
  }

+18 −0
Original line number Diff line number Diff line
@@ -45,6 +45,18 @@ void FlagParser::defineStringV(
  flags_.emplace_back(flag_state);
}

void FlagParser::defineBool(
    const char* longopt,
    bool* value) {
  FlagState flag_state;
  flag_state.type = T_BOOL;
  flag_state.required = false;
  flag_state.longopt = longopt;
  flag_state.value = static_cast<void*>(value);
  flag_state.has_value = false;
  flags_.emplace_back(flag_state);
}

void FlagParser::defineSwitch(
    const char* longopt,
    bool* value) {
@@ -107,6 +119,7 @@ ReturnCode parseValue(FlagState* flag, const std::string& value) {
      break;

    case T_SWITCH:
    case T_BOOL:
      if (value == "on") {
        *static_cast<bool*>(flag->value) = true;
      } else if (value == "off") {
@@ -218,6 +231,11 @@ ReturnCode FlagParser::parseArgv(const std::vector<std::string>& argv) {
      if (!rc) {
        return rc;
      }
    } else if (flag_ptr->type == T_SWITCH) {
      auto rc = parseValue(flag_ptr, "on");
      if (!rc) {
        return rc;
      }
    } else {
      if (i + 1 < argv.size()) {
        auto rc = parseValue(flag_ptr, argv[++i]);
+8 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
namespace fviz {

enum kFlagType {
  T_BOOL,
  T_SWITCH,
  T_STRING,
  T_STRING_V,
@@ -56,6 +57,13 @@ public:
      const char* longopt,
      std::vector<std::string>* value);

  /**
   * Define a boolean flag
   */
  void defineBool(
      const char* longopt,
      bool* value);

  /**
   * Define a boolean flag
   */
+32 −0
Original line number Diff line number Diff line
Command Line
============

The primary method for translate input expressions to SVG or PNG output files is
the `fviz` command line program. A typical invocation looks like this:

    $ fviz --in my_chart.fvz --out my_chart.svg

See below for a full list of supported command line options. Besides the command
line interface, fviz also offers a C API that can be used to render charts
directly from your application.


List of command line flags
--------------------------

Below you can find a list of all currently supported command line arguments.

    Usage: $ fviz [OPTIONS]
      --in <path>               Path to the input file
      --out <path>              Path to the output file
      --outfmt <format>         Output format. If no format is given, it is inferred from the
                                filename. Valid values: 'png', 'svg'
      --font-defaults <bool>    Enable or disable default font loading. Default is enabled.
                                Valid values: 'on' and 'off'
      --font-load <path>        Add a font file to the default font list
      --debug                   Run in debug mode
      --help                    Display this help text and exit
      --version                 Display the version of this binary and exit

    Examples:
      $ fviz --in my_chart.fvz --out my_chart.svg
+4 −0
Original line number Diff line number Diff line
@@ -67,6 +67,10 @@ documentation:
      #  title: "Values & Units"
      #  url: "/documentation/units"
      #  file: "units"
        -
          title: "Command Line"
          url: "/documentation/command-line"
          file: "reference/command_line"
        -
          title: "Colors"
          url: "/documentation/colors"