Skip to content

Commit

Permalink
Merge pull request #1292 from operable/vanstee/remove-subcommands
Browse files Browse the repository at this point in the history
Remove subcommands from codebase
  • Loading branch information
Kevin Smith authored Jan 8, 2017
2 parents 50aa078 + cf16201 commit 25e9679
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 40 deletions.
1 change: 0 additions & 1 deletion lib/cog/bundle/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ defmodule Cog.Bundle.Config do
"examples" => GenCommand.Base.examples(module),
"notes" => GenCommand.Base.notes(module),
"arguments" => GenCommand.Base.arguments(module),
"subcommands" => GenCommand.Base.subcommands(module),
"output" => GenCommand.Base.output(module),
"documentation" => case Code.get_docs(module, :moduledoc) do
{_line, doc} ->
Expand Down
3 changes: 1 addition & 2 deletions lib/cog/command/gen_command/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ defmodule Cog.Command.GenCommand.Base do
Module.register_attribute(__MODULE__, :examples, accumulate: false, persist: true)
Module.register_attribute(__MODULE__, :notes, accumulate: false, persist: true)
Module.register_attribute(__MODULE__, :arguments, accumulate: false, persist: true)
Module.register_attribute(__MODULE__, :subcommands, accumulate: false, persist: true)
Module.register_attribute(__MODULE__, :options, accumulate: true, persist: true)
Module.register_attribute(__MODULE__, :permissions, accumulate: true, persist: true)
Module.register_attribute(__MODULE__, :raw_rules, accumulate: true, persist: false)
Expand Down Expand Up @@ -180,7 +179,7 @@ defmodule Cog.Command.GenCommand.Base do
attr_value(module, :command_name)
end

for attr <- [:description, :long_description, :examples, :notes, :arguments, :subcommands, :output_description, :output_example] do
for attr <- [:description, :long_description, :examples, :notes, :arguments, :output_description, :output_example] do
def unquote(attr)(module),
do: attr_value(module, unquote(attr))
end
Expand Down
1 change: 0 additions & 1 deletion lib/cog/commands/help.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ defmodule Cog.Commands.Help do
@output_example """
{
"synopsis": "operable:raw",
"subcommands": [],
"required_options": [],
"output": {},
"options": [],
Expand Down
13 changes: 0 additions & 13 deletions lib/cog/commands/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ defmodule Cog.Commands.Helpers do
end
end

@doc """
Returns a tuple containing the subcommand and remaining args
"""
@spec get_subcommand(List.t) :: {String.t, List.t}
def get_subcommand([]),
do: {nil, []}
def get_subcommand([subcommand | args]),
do: {subcommand, args}

@doc """
If flag exists and is true will return true, otherwise returns false. Flags
are defined as boolean options. Options that are not.
Expand Down Expand Up @@ -123,10 +114,6 @@ defmodule Cog.Commands.Helpers do
do: "Invalid alias name. Only emoji, letters, numbers, and the following special characters are allowed: *, -, _"
def error(:too_many_wildcards),
do: "Too many wildcards. You can only include one wildcard in a query"
def error(:no_subcommand),
do: "I don't what to do, please specify a subcommand"
def error({:unknown_subcommand, subcommand}),
do: "Unknown subcommand '#{subcommand}'"
def error({:resource_not_found, "rule", id}),
do: "Could not find 'rule' with the id '#{id}'"
def error({:resource_not_found, resource_type, resource_name}),
Expand Down
3 changes: 1 addition & 2 deletions lib/cog/models/command_version.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ defmodule Cog.Models.CommandVersion do
field :examples, :string
field :notes, :string
field :arguments, :string
field :subcommands, :map
field :documentation, :string
field :output, :map
field :status, :string, virtual: true
Expand All @@ -28,7 +27,7 @@ defmodule Cog.Models.CommandVersion do
end

@required_fields ~w(command_id bundle_version_id)
@optional_fields ~w(description documentation long_description examples notes arguments subcommands output)
@optional_fields ~w(description documentation long_description examples notes arguments output)

summary_fields [:documentation]
detail_fields [:documentation]
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"ranch": {:hex, :ranch, "1.2.1", "a6fb992c10f2187b46ffd17ce398ddf8a54f691b81768f9ef5f461ea7e28c762", [:make], []},
"romeo": {:git, "https://github.com/operable/romeo.git", "65106b94f134a12791ec63fa284b0ce5e9358538", [branch: "iq-bodies"]},
"slack": {:git, "https://github.com/operable/Elixir-Slack.git", "4d6a3c4036ec4129e8d77e55cd1d3e62093cc001", []},
"spanner": {:git, "https://github.com/operable/spanner.git", "57df53144d9c9bf589bbaf60014840be2aa57a6d", []},
"spanner": {:git, "https://github.com/operable/spanner.git", "fca6da5bfe738de87f1027e93677ba971c787110", []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:rebar, :make], []},
"table_rex": {:hex, :table_rex, "0.8.3", "1c68dfc6886d6f118f5047b0449d6402ae0ac5709064789e578c2f4659f4064b", [:mix], []},
"uuid": {:hex, :uuid, "1.1.5", "96cb36d86ee82f912efea4d50464a5df606bf3f1163d6bdbb302d98474969369", [], []},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Cog.Repo.Migrations.RemoveSubcommandsFromCommandVersions do
use Ecto.Migration

def change do
alter table(:command_versions) do
remove :subcommands
end
end
end
10 changes: 0 additions & 10 deletions priv/templates/embedded/help-command.greenbar
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ __Options__
~br~
~end~

~if cond=$command.subcommands not_empty?~
__Subcommands__
~br~
~each var=$command.subcommands as=subcommand~
* ~$subcommand.command~ - ~$subcommand.description~

~end~
~br~
~end~

~if cond=$command.examples~
__Examples__
~br~
Expand Down
10 changes: 0 additions & 10 deletions web/views/command_version_help_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ defmodule Cog.CommandVersionHelpView do
synopsis: render_synopsis(command_version),
required_options: render_required_options(command_version),
options: render_options(command_version),
subcommands: render_subcommands(command_version),
examples: command_version.examples,
notes: command_version.notes,
output: render_output(command_version),
Expand Down Expand Up @@ -95,15 +94,6 @@ defmodule Cog.CommandVersionHelpView do
defp render_long_flag(%CommandOption{long_flag: long_flag, name: name}),
do: "--#{long_flag} <#{name}>"

def render_subcommands(%CommandVersion{subcommands: nil}),
do: []
def render_subcommands(%CommandVersion{subcommands: subcommands}) do
Enum.map(subcommands, fn {command, description} ->
%{command: command,
description: description}
end)
end

def render_output(%CommandVersion{output: output}) do
%{description: output["description"],
example: output["example"]}
Expand Down

0 comments on commit 25e9679

Please sign in to comment.