Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port commands to use AbstractCommand #62

Merged
merged 1 commit into from
Apr 3, 2024
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
62 changes: 30 additions & 32 deletions cmd/alias.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
# frozen_string_literal: true

require "cli/parser"
require "abstract_command"
require_relative "../lib/aliases"

module Homebrew
module_function

def alias_args
Homebrew::CLI::Parser.new do
usage_banner "`alias` [<alias> ... | <alias>=<command>]"
description <<~EOS
Show existing aliases. If no aliases are given, print the whole list.
EOS
switch "--edit",
description: "Edit aliases in a text editor. Either one or all aliases may be opened at once. " \
"If the given alias doesn't exist it'll be pre-populated with a template."
named_args max: 1
end
end

def alias
args = alias_args.parse
module Cmd
class Alias < AbstractCommand
cmd_args do
usage_banner "`alias` [<alias> ... | <alias>=<command>]"
description <<~EOS
Show existing aliases. If no aliases are given, print the whole list.
EOS
switch "--edit",
description: "Edit aliases in a text editor. Either one or all aliases may be opened at once. " \
"If the given alias doesn't exist it'll be pre-populated with a template."
named_args max: 1
end

arg = args.named.first
split_arg = arg.split("=", 2) if arg.present?
def run
arg = args.named.first
split_arg = arg.split("=", 2) if arg.present?

Aliases.init
Aliases.init

if args.edit?
if arg.blank?
Aliases.edit_all
else
Aliases.edit arg
if args.edit?
if arg.blank?
Aliases.edit_all
else
Aliases.edit arg
end
elsif /.=./.match?(arg)
Aliases.add(*split_arg)
elsif arg.present?
Aliases.show arg
else
Aliases.show
end
end
elsif /.=./.match?(arg)
Aliases.add(*split_arg)
elsif arg.present?
Aliases.show arg
else
Aliases.show
end
end
end
28 changes: 13 additions & 15 deletions cmd/unalias.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
# frozen_string_literal: true

require "cli/parser"
require "abstract_command"
require_relative "../lib/aliases"

module Homebrew
module_function
module Cmd
class Unalias < AbstractCommand
cmd_args do
description <<~EOS
Remove aliases.
EOS
named_args :alias, min: 1
end

def unalias_args
Homebrew::CLI::Parser.new do
description <<~EOS
Remove aliases.
EOS
named_args :alias, min: 1
def run
Aliases.init
args.named.each { |a| Aliases.remove a }
end
end
end

def unalias
args = unalias_args.parse

Aliases.init
args.named.each { |a| Aliases.remove a }
end
end