2023-10-25 12:01:46 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#
|
|
|
|
# SPDX-FileCopyrightText: 2023 Glenn Y. Rolland <glenux@glenux.net>
|
|
|
|
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
|
2023-10-22 21:23:56 +00:00
|
|
|
|
2023-10-23 21:11:12 +00:00
|
|
|
require "option_parser"
|
2023-10-22 21:23:56 +00:00
|
|
|
require "./config"
|
2023-11-18 22:55:13 +00:00
|
|
|
require "./version"
|
2024-01-14 19:31:38 +00:00
|
|
|
require "./parsers/root_parser"
|
|
|
|
require "./utils/breadcrumbs"
|
|
|
|
require "./utils/fzf"
|
|
|
|
require "./file_system_manager"
|
|
|
|
require "./command_factory"
|
2023-10-22 21:23:56 +00:00
|
|
|
|
|
|
|
module GX
|
|
|
|
class Cli
|
2023-11-18 18:32:12 +00:00
|
|
|
Log = ::Log.for("cli")
|
2023-10-23 21:11:12 +00:00
|
|
|
|
2024-01-14 19:31:38 +00:00
|
|
|
@config : GX::Config
|
2023-10-22 21:23:56 +00:00
|
|
|
|
2024-01-14 19:31:38 +00:00
|
|
|
def initialize
|
2023-10-22 21:23:56 +00:00
|
|
|
# Main execution starts here
|
2024-01-14 19:31:38 +00:00
|
|
|
# # FIXME: add a method to verify that FZF is installed
|
2023-10-23 21:11:12 +00:00
|
|
|
@config = Config.new
|
2023-10-22 21:23:56 +00:00
|
|
|
end
|
|
|
|
|
2023-10-23 21:11:12 +00:00
|
|
|
def parse_command_line(args)
|
|
|
|
pparser = OptionParser.new do |parser|
|
2024-01-14 19:31:38 +00:00
|
|
|
breadcrumbs = Utils::BreadCrumbs.new([] of String)
|
|
|
|
Parsers::RootParser.new.build(parser, breadcrumbs, @config)
|
2023-10-23 21:11:12 +00:00
|
|
|
end
|
|
|
|
pparser.parse(args)
|
|
|
|
end
|
|
|
|
|
2024-01-14 19:31:38 +00:00
|
|
|
def run
|
|
|
|
command = CommandFactory.create_command(@config, @config.mode)
|
|
|
|
abort("ERROR: unknown command for mode #{@config.mode}") if command.nil?
|
2023-11-24 09:25:30 +00:00
|
|
|
|
2024-01-14 19:31:38 +00:00
|
|
|
command.try &.execute
|
2023-10-22 21:23:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|