mfm/src/cli.cr

43 lines
1 KiB
Crystal
Raw Normal View History

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
require "option_parser"
2023-10-22 21:23:56 +00:00
require "./config"
require "./version"
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
Log = ::Log.for("cli")
@config : GX::Config
2023-10-22 21:23:56 +00:00
def initialize
2023-10-22 21:23:56 +00:00
# Main execution starts here
# # FIXME: add a method to verify that FZF is installed
@config = Config.new
2023-10-22 21:23:56 +00:00
end
def parse_command_line(args)
pparser = OptionParser.new do |parser|
breadcrumbs = Utils::BreadCrumbs.new([] of String)
Parsers::RootParser.new.build(parser, breadcrumbs, @config)
end
pparser.parse(args)
end
def run
command = CommandFactory.create_command(@config, @config.mode)
abort("ERROR: unknown command for mode #{@config.mode}") if command.nil?
command.try &.execute
2023-10-22 21:23:56 +00:00
end
end
end