Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/lib/linear_cli/cli/commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@ defmodule LinearCli.CLI.Commands do
end
end

@doc "Ported from commands/version.rb."
def version(_result) do
IO.puts(to_string(Application.spec(:linear_cli, :vsn)))
@doc """
Ported from commands/version.rb, extended to respect the global
`--output json` option like every other command does - previously
ignored it and always printed plain text.
"""
def version(%{options: options}) do
version = to_string(Application.spec(:linear_cli, :vsn))

if options.output == "json" do
IO.puts(Jason.encode!(%{version: version}))
else
Comment on lines +24 to +28
IO.puts(version)
end

:ok
end

Expand Down
6 changes: 6 additions & 0 deletions app/test/linear_cli/cli_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ defmodule LinearCli.CLITest do
assert capture_io(fn -> LinearCli.CLI.main(["version"]) end) =~ version
end

test "version -o json prints valid JSON with the version field" do
version = to_string(Application.spec(:linear_cli, :vsn))
output = capture_io(fn -> LinearCli.CLI.main(["version", "-o", "json"]) end)
assert %{"version" => ^version} = Jason.decode!(output)
end

test "--develop and --butwhy are rewritten to their canonical --dev/--reason spellings" do
# Ruby's create.rb declares `--dev` with alias `--develop`, and update.rb's
# `--reason` has alias `--butwhy` - both real, user-facing spellings.
Expand Down