Compare commits

...

3 commits

Author SHA1 Message Date
093c9d2fa1 feat: add parser support for completion
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
2024-08-04 22:19:36 +02:00
b1567a1aa0 feat: add base classes for handling completion 2024-08-04 22:14:10 +02:00
a51ce2e98f feat: add basic zsh completion script 2024-08-04 22:12:59 +02:00
6 changed files with 63 additions and 1 deletions

View file

@ -0,0 +1,17 @@
require "./abstract_command"
module GX::Commands
class CompletionAutodetect < AbstractCommand
def initialize(@config : GX::Config)
end
def execute
STDERR.puts "FIXME: Completion auto-detection isn't implemented yet. Please select one of the following: --bash or --zsh"
exit(0)
end
def self.handles_mode
GX::Types::Mode::CompletionAutodetect
end
end
end

View file

@ -0,0 +1,17 @@
require "./abstract_command"
module GX::Commands
class CompletionBash < AbstractCommand
def initialize(@config : GX::Config)
end
def execute
completion_bash = FileStorage.get("completion.bash")
STDOUT.puts completion_bash.gets_to_end
end
def self.handles_mode
GX::Types::Mode::CompletionBash
end
end
end

View file

@ -0,0 +1,17 @@
require "./abstract_command"
module GX::Commands
class CompletionZsh < AbstractCommand
def initialize(@config : GX::Config)
end
def execute
completion_bash = FileStorage.get("completion.zsh")
STDOUT.puts completion_bash.gets_to_end
end
def self.handles_mode
GX::Types::Mode::CompletionZsh
end
end
end

View file

@ -4,6 +4,7 @@ module GX::Parsers
class CompletionParser < AbstractParser
def build(parser, ancestors, config)
breadcrumbs = ancestors + "completion"
# config.mode = Types::Mode::CompletionAutodetect
parser.banner = Utils.usage_line(
breadcrumbs,
@ -13,10 +14,12 @@ module GX::Parsers
parser.separator("\nCompletion commands:")
parser.on("--bash", "Generate bash completion") do |_|
config.mode = Types::Mode::CompletionBash
Log.info { "Set bash completion" }
end
parser.on("--zsh", "Generate zsh completion") do |_|
config.mode = Types::Mode::CompletionZsh
Log.info { "Set zsh completion" }
end

View file

@ -69,7 +69,10 @@ module GX::Parsers
# end
parser.on("completion", "Manage completion") do
config.mode = Types::Mode::GlobalCompletion
config.mode = Types::Mode::GlobalHelp
config.help_options = Parsers::Options::HelpOptions.new
config.help_options.try(&.parser_snapshot=(parser.dup))
Parsers::CompletionParser.new.build(parser, breadcrumbs, config)
end

View file

@ -0,0 +1,5 @@
#!/bin/zsh
# mfm Zsh completion script