Module: PMLCode::CLI
- Defined in:
- lib/pmlcode/cli.rb
Constant Summary collapse
- USAGE =
"## USAGE\n\n pmlcode [PML_PATH, ...] [OPTIONS]\n\nPML_PATHs can optionally include a :LINENUM suffix.\n\n## SYNOPSIS\n\nLooks for `<embed>` tags whose `file` attribute match `--pattern`, extracting the\nfollowing metadata:\n\n- `coderoot`: The relative path from the source PML's directory\n- `chapter`: A chapter identifier\n- `snapshot`: A snapshot of the code at a specific point in the chapter\n- `path`: The path to the file within the target `--application-directory` project\n\nFor example, given this embed, using the default --pattern:\n\n <embed file=\"code/02-testing/01-start/test/some_test.exs\"/>\n\nThis is the metadata:\n\ncoderoot\n: `code`\n\nchapter\n: `02-testing`\n\nsnapshot\n: `01-start`\n\npath\n: `test/some_test.exs`\n\nThis file will be extracted by looking at the repository located at --application-directory,\nand trying to find a ref _on its remote origin_ that matches the `chapter.snapshot`, i.e.:\n\n `origin/02-testing.01-start`\n\nThen pulling `test/some_test.exs` (or the entire branch, if `--type full` is being used).\n\n## ENVIRONMENT VARIABLES\n\nPMLCODE_APP_DIR\n: An optional working copy directory path, sets the default\n for `--application-directory`\n\nPMLCODE_PATTERN\n: An optional pattern, sets the default for `--pattern`\n\n## CUSTOM PATTERNS\n\nAny custom pattern must have named captures for `coderoot`, `chapter`, `snapshot`, and `path`.\n\n## CUSTOM BRANCH/REFS\n\nCurrently the ref retrieved from git repositories is always in the form `chapter.snapshot`,\nusing the information matched using the --pattern.\n\n## OPTIONS\n\n"- REQUIRED_PATTERN_CAPTURES =
%w(coderoot chapter snapshot path)- DEFAULT_PATTERN =
/^(?<coderoot>[^\/]+)\/(?<chapter>[^\/]+)\/(?<snapshot>[^\/]+)\/(?<path>.+)$/- DEFAULTS =
{ type: :sparse, app: ENV["PMLCODE_APP_DIR"], pattern: ENV["PMLCODE_PATTERN"] ? Regexp.new(ENV["PMLCODE_PATTERN"]) : DEFAULT_PATTERN }.freeze
Class Method Summary collapse
Class Method Details
.run(args) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/pmlcode/cli.rb', line 79 def self.run(args) = OpenStruct.new(DEFAULTS) # Parse arguments parser = build_parser() parser.parse!(args) sources = prepare(, parser, args) sources.each do |source| .source = source .output = File.dirname(source.path) update!() end end |