Skip to content

Commit

Permalink
Group cli options in sections
Browse files Browse the repository at this point in the history
  • Loading branch information
pnezis committed Jul 11, 2024
1 parent 0c86c8a commit a057b12
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 26 deletions.
2 changes: 1 addition & 1 deletion workspace/lib/mix/tasks/workspace.check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Mix.Tasks.Workspace.Check do
## Command Line Options
#{CliOptions.docs(@options_schema, sort: true)}
#{CliOptions.docs(@options_schema, sort: true, sections: Workspace.CliOptions.doc_sections())}
"""

use Mix.Task
Expand Down
5 changes: 3 additions & 2 deletions workspace/lib/mix/tasks/workspace.graph.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ defmodule Mix.Tasks.Workspace.Graph do
doc: """
If set the project's tags are also included in the generated graph. Currently
applicable only for `:pretty` and `:plain` formatters.
"""
""",
doc_section: :display
],
focus: [
type: :string,
Expand Down Expand Up @@ -154,7 +155,7 @@ defmodule Mix.Tasks.Workspace.Graph do
## Command Line Options
#{CliOptions.docs(@options_schema, sort: true)}
#{CliOptions.docs(@options_schema, sort: true, sections: Workspace.CliOptions.doc_sections())}
"""
use Mix.Task
alias Workspace.Graph.Formatter
Expand Down
14 changes: 9 additions & 5 deletions workspace/lib/mix/tasks/workspace.list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@ defmodule Mix.Tasks.Workspace.List do
associated metadata. By default it will be saved in `workspace.json` in the
current directory. You can override the output path by setting the `--output`
option.
"""
""",
doc_section: :export
],
output: [
type: :string,
default: "workspace.json",
doc: """
The output file. Applicable only if `--json` is set.
"""
""",
doc_section: :export
],
relative_paths: [
type: :boolean,
default: false,
doc: """
If set the paths in the exported json file will be relative with respect to the
workspace path. Applicable only if `--json` is set.
"""
""",
doc_section: :export
],
maintainer: [
type: :string,
doc: """
Search for projects with the given maintainer. A partial case insensitive string search
is performed so you can provide only part of the maintainer's name.
"""
""",
doc_section: :filtering
]
]

Expand Down Expand Up @@ -63,7 +67,7 @@ defmodule Mix.Tasks.Workspace.List do
## Command line options
#{CliOptions.docs(@options_schema, sort: true)}
#{CliOptions.docs(@options_schema, sort: true, sections: Workspace.CliOptions.doc_sections())}
## Filtering projects
Expand Down
8 changes: 5 additions & 3 deletions workspace/lib/mix/tasks/workspace.run.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defmodule Mix.Tasks.Workspace.Run do
],
only_roots: [
type: :boolean,
doc: "If set, the task will be executed only on graph's root nodes."
doc: "If set, the task will be executed only on graph's root nodes.",
doc_section: :status
],
dry_run: [
type: :boolean,
Expand Down Expand Up @@ -56,7 +57,8 @@ defmodule Mix.Tasks.Workspace.Run do
generated with the run results for each project. This may be useful for
your CI/CD automation pipelines, in case you want to post-process the
run results.
"""
""",
doc_section: :export
]
]

Expand Down Expand Up @@ -104,7 +106,7 @@ defmodule Mix.Tasks.Workspace.Run do
## Command-line Options
#{CliOptions.docs(@options_schema, sort: true)}
#{CliOptions.docs(@options_schema, sort: true, sections: Workspace.CliOptions.doc_sections())}
## Filtering runs
Expand Down
2 changes: 1 addition & 1 deletion workspace/lib/mix/tasks/workspace.status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Mix.Tasks.Workspace.Status do
## Command line options
#{CliOptions.docs(@options_schema, sort: true)}
#{CliOptions.docs(@options_schema, sort: true, sections: Workspace.CliOptions.doc_sections())}
"""
use Mix.Task

Expand Down
5 changes: 3 additions & 2 deletions workspace/lib/mix/tasks/workspace.test.coverage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ defmodule Mix.Tasks.Workspace.Test.Coverage do
doc: """
If set to true only the package coverage is reported and not the individual modules
coverages. This has higher priority than the `:verbose` option.
"""
""",
doc_section: :display
]
]

Expand Down Expand Up @@ -200,7 +201,7 @@ defmodule Mix.Tasks.Workspace.Test.Coverage do
## Command line options
#{CliOptions.docs(@options_schema, sort: true)}
#{CliOptions.docs(@options_schema, sort: true, sections: Workspace.CliOptions.doc_sections())}
"""
use Mix.Task

Expand Down
62 changes: 50 additions & 12 deletions workspace/lib/workspace/cli_options.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ defmodule Workspace.CliOptions do
multiple: true,
short: "p",
doc:
"The project name, can be defined multiple times. If not set all projects are considered"
"The project name, can be defined multiple times. If not set all projects are considered",
doc_section: :filtering
],
exclude: [
type: :string,
short: "e",
multiple: true,
doc: "Ignore the given projects"
doc: "Ignore the given projects",
doc_section: :filtering
],
tags: [
type: :string,
Expand All @@ -24,7 +26,8 @@ defmodule Workspace.CliOptions do
If set, only projects with the given tag(s) will be considered. For scoped tags you should
provide a colon separated string (examples: `shared`, `scope:api`, `type:utils`). For
excluding a specific tag use `--exclude-tag`
"""
""",
doc_section: :filtering
],
excluded_tags: [
type: :string,
Expand All @@ -34,49 +37,58 @@ defmodule Workspace.CliOptions do
If set, any projects with any of the given tag(s) will be excluded. For scoped tags you should
provide a colon separated string (examples: `shared`, `scope:api`, `type:utils`). For selecting
a specific tag use `--tag`
"""
""",
doc_section: :filtering
],
affected: [
type: :boolean,
short: "a",
doc: "Run only on affected projects"
doc: "Run only on affected projects",
doc_section: :status
],
modified: [
type: :boolean,
short: "m",
doc: "Run only on modified projects"
doc: "Run only on modified projects",
doc_section: :status
],
verbose: [
type: :boolean,
doc: "If set enables verbose logging"
doc: "If set enables verbose logging",
doc_section: :display
],
workspace_path: [
type: :string,
doc: "If set it specifies the root workspace path, defaults to current directory"
doc: "If set it specifies the root workspace path, defaults to current directory",
doc_section: :workspace
],
config_path: [
type: :string,
doc: "The path to the workspace config to be used, relative to the workspace path",
default: ".workspace.exs"
default: ".workspace.exs",
doc_section: :workspace
],
show_status: [
type: :boolean,
default: false,
doc: "If set the status of each project will be included in the output graph"
doc: "If set the status of each project will be included in the output graph",
doc_section: :display
],
base: [
type: :string,
doc: """
The base git reference to compare the head to. Applied only when `--affected` or `--modified`
are set.
"""
""",
doc_section: :status
],
head: [
type: :string,
default: "HEAD",
doc: """
A reference to the git head. Applied only if `--base` is set for getting the changed files
"""
""",
doc_section: :status
]
]

Expand All @@ -87,4 +99,30 @@ defmodule Workspace.CliOptions do
@doc false
@spec option(key :: atom()) :: keyword()
def option(key), do: Keyword.fetch!(@default_cli_options, key)

@doc false
@spec doc_sections() :: keyword()
def doc_sections do
[
status: [
header: "Workspace status options",
doc: """
Status is retrieved from the diff between the given `--base` and `--head`. Knowing the
changed files we can limit the execution of workspace commands only to relevant projects.
"""
],
filtering: [
header: "Filtering options"
],
display: [
header: "Display options"
],
export: [
header: "Export options"
],
workspace: [
header: "Global workspace options"
]
]
end
end

0 comments on commit a057b12

Please sign in to comment.