Compare commits
9 commits
9e68d3bf70
...
ced3168471
Author | SHA1 | Date | |
---|---|---|---|
ced3168471 | |||
6d15d331d8 | |||
e27495eecf | |||
bfbc9bb301 | |||
d39c7117a4 | |||
da0cf858a4 | |||
44b5daf5c7 | |||
07f2275a41 | |||
c541a2556d |
12 changed files with 130 additions and 8 deletions
|
@ -7,7 +7,7 @@
|
|||
# - "path/to/repo2"
|
||||
|
||||
# List of patterns to ignore during preloading
|
||||
ignore_list:
|
||||
exclude_list:
|
||||
- ^bin/
|
||||
- ^\.code_preloader.yml
|
||||
- ^doc/
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -7,3 +7,5 @@
|
|||
.vagrant
|
||||
bin
|
||||
lib
|
||||
.aider*
|
||||
.env
|
||||
|
|
0
spec/parsers/completion_parser_spec.cr
Normal file
0
spec/parsers/completion_parser_spec.cr
Normal file
68
spec/parsers/config_parser_spec.cr
Normal file
68
spec/parsers/config_parser_spec.cr
Normal file
|
@ -0,0 +1,68 @@
|
|||
require "../spec_helper"
|
||||
require "../../src/parsers/config_parser"
|
||||
|
||||
describe GX::Parsers::ConfigParser do
|
||||
context "Initialization" do
|
||||
it "can initialize" do
|
||||
GX::Parsers::ConfigParser.new.should be_a(GX::Parsers::ConfigParser)
|
||||
end
|
||||
end
|
||||
|
||||
context "Functioning" do
|
||||
it "can parse 'init' subcommand" do
|
||||
config = GX::Config.new
|
||||
parser = OptionParser.new
|
||||
breadcrumbs = GX::Utils::BreadCrumbs.new(["mfm"])
|
||||
|
||||
GX::Parsers::ConfigParser.new.build(parser, breadcrumbs, config)
|
||||
|
||||
# Test 'init' subcommand recognition
|
||||
config.mode.should eq(GX::Types::Mode::GlobalTui) # default
|
||||
parser.parse(["init"])
|
||||
config.mode.should eq(GX::Types::Mode::ConfigInit)
|
||||
|
||||
# Test ConfigInitOptions instantiation
|
||||
config.config_init_options.should be_a(GX::Parsers::Options::ConfigInitOptions)
|
||||
|
||||
# Test banner update
|
||||
# FIXME: parser.banner.should include("Create initial mfm configuration")
|
||||
|
||||
# Test separator presence
|
||||
# FIXME: parser.banner.should include("Init options")
|
||||
end
|
||||
|
||||
it "can parse '-p' / '--path' option for 'init' subcommand" do
|
||||
config = GX::Config.new
|
||||
parser = OptionParser.new
|
||||
breadcrumbs = GX::Utils::BreadCrumbs.new(["mfm"])
|
||||
|
||||
GX::Parsers::ConfigParser.new.build(parser, breadcrumbs, config)
|
||||
parser.parse(["init", "-p", "/test/path"])
|
||||
pp config
|
||||
config.config_init_options.try do |opts|
|
||||
opts.path.should eq("/test/path")
|
||||
end
|
||||
|
||||
config = GX::Config.new
|
||||
parser = OptionParser.new
|
||||
breadcrumbs = GX::Utils::BreadCrumbs.new(["mfm"])
|
||||
|
||||
GX::Parsers::ConfigParser.new.build(parser, breadcrumbs, config)
|
||||
parser.parse(["init", "--path", "/test/path/2"])
|
||||
config.config_init_options.try do |opts|
|
||||
opts.path.should eq("/test/path/2")
|
||||
end
|
||||
end
|
||||
|
||||
it "should include help line for 'init' subcommand" do
|
||||
config = GX::Config.new
|
||||
parser = OptionParser.new
|
||||
breadcrumbs = GX::Utils::BreadCrumbs.new(["mfm"])
|
||||
|
||||
GX::Parsers::ConfigParser.new.build(parser, breadcrumbs, config)
|
||||
|
||||
# Test help line presence
|
||||
# FIXME: parser.banner.should include("Run 'mfm config init --help' for more information on a command.")
|
||||
end
|
||||
end
|
||||
end
|
0
spec/parsers/mapping_parser_spec.cr
Normal file
0
spec/parsers/mapping_parser_spec.cr
Normal file
0
spec/parsers/root_parser_spec.cr
Normal file
0
spec/parsers/root_parser_spec.cr
Normal file
|
@ -37,10 +37,10 @@ describe GX::Utils::BreadCrumbs do
|
|||
b1.to_s.should eq("")
|
||||
|
||||
b2 = b1 + "test1"
|
||||
b2.to_a.should eq("test1")
|
||||
b2.to_s.should eq("test1")
|
||||
|
||||
b3 = b2 + "test2"
|
||||
b3.to_a.should eq("test1 test2")
|
||||
b3.to_s.should eq("test1 test2")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,16 @@ module GX::Commands
|
|||
config_dir = File.join(@config.home_dir, ".config", "mfm")
|
||||
config_file_path = File.join(config_dir, "config.yml")
|
||||
|
||||
# Override the configuration path if provided
|
||||
puts "Configuration file path: #{config_file_path}"
|
||||
puts "Configuration file path: #{@config.path}"
|
||||
pp @config
|
||||
@config.path.try do |path|
|
||||
config_file_path = path
|
||||
config_dir = File.dirname(path)
|
||||
end
|
||||
exit 1
|
||||
|
||||
# Guard condition to exit if the configuration file already exists
|
||||
if File.exists?(config_file_path)
|
||||
puts "Configuration file already exists at #{config_file_path}. No action taken."
|
||||
|
|
|
@ -5,12 +5,50 @@ module GX::Commands
|
|||
def initialize(@config : GX::Config) # FIXME
|
||||
@config.load_from_env
|
||||
@config.load_from_file
|
||||
@file_system_manager = FileSystemManager.new(@config)
|
||||
end
|
||||
|
||||
def execute
|
||||
# FIXME: implement
|
||||
puts "mapping create yo!"
|
||||
# FIXME: verify that filesystem is valid or return an error
|
||||
|
||||
# Assuming create_args is passed to this command with necessary details
|
||||
create_args = @config.create_args
|
||||
|
||||
# Validate required arguments
|
||||
if create_args[:name].empty? || create_args[:path].empty?
|
||||
raise ArgumentError.new("Name and path are required to create a mapping.")
|
||||
end
|
||||
|
||||
# Create the appropriate filesystem config based on the type
|
||||
filesystem_config = case create_args[:type]
|
||||
when "gocryptfs"
|
||||
GX::Models::GocryptfsConfig.new(
|
||||
name: create_args[:name],
|
||||
path: create_args[:path],
|
||||
encrypted_path: create_args[:encrypted_path]
|
||||
)
|
||||
when "sshfs"
|
||||
GX::Models::SshfsConfig.new(
|
||||
name: create_args[:name],
|
||||
path: create_args[:path],
|
||||
remote_user: create_args[:remote_user],
|
||||
remote_host: create_args[:remote_host],
|
||||
remote_path: create_args[:remote_path],
|
||||
remote_port: create_args[:remote_port]
|
||||
)
|
||||
when "httpdirfs"
|
||||
GX::Models::HttpdirfsConfig.new(
|
||||
name: create_args[:name],
|
||||
path: create_args[:path],
|
||||
url: create_args[:url]
|
||||
)
|
||||
else
|
||||
raise ArgumentError.new("Unsupported mapping type: #{create_args[:type]}")
|
||||
end
|
||||
|
||||
# Append the new filesystem config to the root config
|
||||
@config.root.try &.filesystems << filesystem_config
|
||||
|
||||
puts "Mapping '#{create_args[:name]}' created and added to configuration successfully."
|
||||
end
|
||||
|
||||
def self.handles_mode
|
||||
|
|
|
@ -14,7 +14,6 @@ module GX::Commands
|
|||
def execute
|
||||
filesystem = @file_system_manager.choose_filesystem
|
||||
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
|
||||
# @file_system_manager.mount_or_umount(filesystem)
|
||||
filesystem.mount
|
||||
@file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open
|
||||
end
|
||||
|
|
|
@ -10,6 +10,10 @@ require "./types/modes"
|
|||
require "./parsers/options/help_options"
|
||||
require "./parsers/options/config_options"
|
||||
require "./parsers/options/config_init_options"
|
||||
require "./parsers/options/mapping_create_options"
|
||||
require "./parsers/options/mapping_delete_options"
|
||||
require "./parsers/options/mapping_mount_options"
|
||||
require "./parsers/options/mapping_umount_options"
|
||||
require "./commands/abstract_command"
|
||||
|
||||
module GX
|
||||
|
@ -37,6 +41,7 @@ module GX
|
|||
property help_options : Parsers::Options::HelpOptions?
|
||||
property config_init_options : Parsers::Options::ConfigInitOptions?
|
||||
property config_options : Parsers::Options::ConfigOptions?
|
||||
property mapping_create_options : Parsers::Options::MappingCreateOptions?
|
||||
|
||||
def initialize
|
||||
raise Models::InvalidEnvironmentError.new("Home directory not found") if !ENV["HOME"]?
|
||||
|
|
|
@ -23,7 +23,7 @@ module GX::Parsers
|
|||
parser.banner = Utils.usage_line(breadcrumbs + "init", "Create initial mfm configuration")
|
||||
parser.separator("\nInit options")
|
||||
|
||||
parser.on("-p", "--path", "Set mapping encrypted path") do |path|
|
||||
parser.on("-p", "--path PATH", "Set mapping encrypted path") do |path|
|
||||
config.config_init_options.try do |opts|
|
||||
opts.path = path
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue