From aec45eebd44d5b63cdcaec1eb79e9476a3210c01 Mon Sep 17 00:00:00 2001 From: Glenn Date: Mon, 15 Jan 2024 09:08:36 +0100 Subject: [PATCH 01/53] fix: replace vault by mapping As the software object has evolved along the way, and the handling of vaults has become generic FUSE filesystems mapping management, we need to correct all the places that still mention vaults. --- src/file_system_manager.cr | 2 +- src/models/concerns/base.cr | 2 +- src/parsers/config_parser.cr | 2 +- src/parsers/mapping_parser.cr | 20 ++++++++++++-------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/file_system_manager.cr b/src/file_system_manager.cr index 91dc1a8..5c78da6 100644 --- a/src/file_system_manager.cr +++ b/src/file_system_manager.cr @@ -120,7 +120,7 @@ module GX puts ">> #{selected_filesystem.name}".colorize(:yellow) if !selected_filesystem - STDERR.puts "Vault not found: #{selected_filesystem}.".colorize(:red) + STDERR.puts "Mapping not found: #{selected_filesystem}.".colorize(:red) return end return selected_filesystem diff --git a/src/models/concerns/base.cr b/src/models/concerns/base.cr index 90254de..223e155 100644 --- a/src/models/concerns/base.cr +++ b/src/models/concerns/base.cr @@ -46,7 +46,7 @@ module GX::Models::Concerns if result_status.success? puts "Models #{name} is now available on #{mount_point_safe}".colorize(:green) else - puts "Error mounting the vault".colorize(:red) + puts "Error mounting the mapping".colorize(:red) return end end diff --git a/src/parsers/config_parser.cr b/src/parsers/config_parser.cr index b902cd5..f1dfa3f 100644 --- a/src/parsers/config_parser.cr +++ b/src/parsers/config_parser.cr @@ -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 vault encrypted path") do |path| + parser.on("-p", "--path", "Set mapping encrypted path") do |path| config.config_init_options.try do |opts| opts.path = path end diff --git a/src/parsers/mapping_parser.cr b/src/parsers/mapping_parser.cr index fc972a9..5249ade 100644 --- a/src/parsers/mapping_parser.cr +++ b/src/parsers/mapping_parser.cr @@ -23,33 +23,37 @@ module GX::Parsers parser.on("create", "Create mapping") do config.mode = Types::Mode::MappingCreate - - pp parser + # pp parser parser.banner = Utils.usage_line(breadcrumbs + "create", "Create mapping", true) parser.separator("\nCreate options") - parser.on("-n", "--name", "Set vault name") do |name| + parser.on("-t", "--type TYPE", "Set filesystem type") do |type| + add_args = add_args.merge({type: type}) + end + + parser.on("-n", "--name", "Set mapping name") do |name| add_args = add_args.merge({name: name}) end - parser.on("-p", "--path", "Set vault encrypted path") do |path| + + parser.on("-p", "--path", "Set mapping encrypted path") do |path| add_args = add_args.merge({path: path}) end parser.separator(Utils.help_line(breadcrumbs + "create")) end - parser.on("edit", "Edit configuration") do |flag| + parser.on("edit", "Edit configuration") do |_| config.mode = Types::Mode::MappingEdit parser.separator(Utils.help_line(breadcrumbs + "edit")) # abort("FIXME: Not implemented") end - parser.on("mount", "Mount mapping") do |flag| + parser.on("mount", "Mount mapping") do |_| config.mode = Types::Mode::MappingMount parser.separator(Utils.help_line(breadcrumbs + "mount")) # abort("FIXME: Not implemented") end - parser.on("umount", "Umount mapping") do |flag| + parser.on("umount", "Umount mapping") do |_| config.mode = Types::Mode::MappingUmount parser.separator(Utils.help_line(breadcrumbs + "umount")) # abort("FIXME: Not implemented") @@ -61,7 +65,7 @@ module GX::Parsers parser.banner = Utils.usage_line(breadcrumbs + "delete", "Delete mapping", true) parser.separator("\nDelete options") - parser.on("-n", "--name", "Set vault name") do |name| + parser.on("-n", "--name", "Set mapping name") do |name| delete_args = delete_args.merge({name: name}) end parser.separator(Utils.help_line(breadcrumbs + "delete")) -- 2.45.3 From 29ab85a61fd90c473cda4d1cf697c4ecc97be163 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:28 +0100 Subject: [PATCH 02/53] fix: run ameba --fix on config_init.cr --- src/commands/config_init.cr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/commands/config_init.cr b/src/commands/config_init.cr index b9407d3..2171d39 100644 --- a/src/commands/config_init.cr +++ b/src/commands/config_init.cr @@ -6,6 +6,9 @@ module GX::Commands end def execute + puts "FIXME: detect if config is present" + puts "FIXME: compute config path (either default, or from command line)" + puts "FIXME: create config file from default if needed" end def self.handles_mode -- 2.45.3 From 8f1862eb4301c841eb630c5fbcfc94e7c9e19bd4 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:28 +0100 Subject: [PATCH 03/53] fix: run ameba --fix on global_completion.cr --- src/commands/global_completion.cr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/commands/global_completion.cr b/src/commands/global_completion.cr index d1be696..4549818 100644 --- a/src/commands/global_completion.cr +++ b/src/commands/global_completion.cr @@ -6,10 +6,12 @@ module GX::Commands end def execute + puts "FIXME: detect option (either zsh or bash)" + puts "FIXME: output the right file from embedded data" end def self.handles_mode - GX::Types::Mode::GlobalConfig + GX::Types::Mode::GlobalCompletion end end end -- 2.45.3 From 275f66d19d73b774e26510ecfc233b3968cb6f91 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:28 +0100 Subject: [PATCH 04/53] fix: run ameba --fix on file_system_manager.cr --- src/file_system_manager.cr | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/file_system_manager.cr b/src/file_system_manager.cr index 5c78da6..9dc003c 100644 --- a/src/file_system_manager.cr +++ b/src/file_system_manager.cr @@ -89,7 +89,9 @@ module GX end def choose_filesystem - names_display = {} of String => NamedTuple(filesystem: Models::AbstractFilesystemConfig, ansi_name: String) + names_display = {} of String => NamedTuple( + filesystem: Models::AbstractFilesystemConfig, + ansi_name: String) config_root = @config.root return if config_root.nil? @@ -114,7 +116,7 @@ module GX end # # FIXME: feat: allow to sort by name or by filesystem - sorted_values = names_display.values.sort_by { |item| item[:filesystem].name } + sorted_values = names_display.values.sort_by!(&.[:filesystem].name) result_filesystem_name = Utils::Fzf.run(sorted_values.map(&.[:ansi_name])).strip selected_filesystem = names_display[result_filesystem_name][:filesystem] puts ">> #{selected_filesystem.name}".colorize(:yellow) @@ -123,7 +125,7 @@ module GX STDERR.puts "Mapping not found: #{selected_filesystem}.".colorize(:red) return end - return selected_filesystem + selected_filesystem end private def generate_display_name(filesystem : Models::AbstractFilesystemConfig) : String @@ -136,7 +138,7 @@ module GX if ENV["DISPLAY"]? || ENV["WAYLAND_DISPLAY"]? return true end - return false + false end end end -- 2.45.3 From 16bb660fc287f9ec4589a40b4057897c18bf5bd4 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:28 +0100 Subject: [PATCH 05/53] fix: run ameba --fix on base.cr --- src/models/concerns/base.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/concerns/base.cr b/src/models/concerns/base.cr index 223e155..219a456 100644 --- a/src/models/concerns/base.cr +++ b/src/models/concerns/base.cr @@ -31,7 +31,7 @@ module GX::Models::Concerns end end - def _mount_wrapper(&block) : Nil + def _mount_wrapper(&) : Nil mount_point_safe = mount_point return if mount_point_safe.nil? -- 2.45.3 From 531cba0dc7175efb8a25e0a8518440e514b1b9d5 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:28 +0100 Subject: [PATCH 06/53] fix: run ameba --fix on gocryptfs_config.cr --- src/models/gocryptfs_config.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/gocryptfs_config.cr b/src/models/gocryptfs_config.cr index 9013bdf..f6ea5b0 100644 --- a/src/models/gocryptfs_config.cr +++ b/src/models/gocryptfs_config.cr @@ -32,7 +32,7 @@ module GX::Models output: STDOUT, error: STDERR ) - return process.wait + process.wait end end end -- 2.45.3 From f5d28671a2ed46861557aa786924ef8f4c202c59 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:29 +0100 Subject: [PATCH 07/53] fix: run ameba --fix on httpdirfs_config.cr --- src/models/httpdirfs_config.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/httpdirfs_config.cr b/src/models/httpdirfs_config.cr index 30db9eb..bcf0227 100644 --- a/src/models/httpdirfs_config.cr +++ b/src/models/httpdirfs_config.cr @@ -32,7 +32,7 @@ module GX::Models output: STDOUT, error: STDERR ) - return process.wait + process.wait end end end -- 2.45.3 From b59f1011ac3317ccd2b82191c941bd53ad909b62 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:29 +0100 Subject: [PATCH 08/53] fix: run ameba --fix on sshfs_config.cr --- src/models/sshfs_config.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/sshfs_config.cr b/src/models/sshfs_config.cr index 99da441..82b3538 100644 --- a/src/models/sshfs_config.cr +++ b/src/models/sshfs_config.cr @@ -39,7 +39,7 @@ module GX::Models output: STDOUT, error: STDERR ) - return process.wait + process.wait end end end -- 2.45.3 From ed2cf5227f8597eb19b77418fff941aab73d88c4 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:29 +0100 Subject: [PATCH 09/53] fix: run ameba --fix on completion_parser.cr --- src/parsers/completion_parser.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parsers/completion_parser.cr b/src/parsers/completion_parser.cr index 1cdc4cc..3a068f9 100644 --- a/src/parsers/completion_parser.cr +++ b/src/parsers/completion_parser.cr @@ -12,11 +12,11 @@ module GX::Parsers ) parser.separator("\nCompletion commands:") - parser.on("--bash", "Generate bash completion") do |flag| + parser.on("--bash", "Generate bash completion") do |_| Log.info { "Set bash completion" } end - parser.on("--zsh", "Generate zsh completion") do |flag| + parser.on("--zsh", "Generate zsh completion") do |_| Log.info { "Set zsh completion" } end -- 2.45.3 From dbb0a42e91cfb86ef2947e7aeb7818189b3e0d07 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:29 +0100 Subject: [PATCH 10/53] fix: run ameba --fix on mapping_parser.cr --- src/parsers/mapping_parser.cr | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/parsers/mapping_parser.cr b/src/parsers/mapping_parser.cr index 5249ade..60b2d7a 100644 --- a/src/parsers/mapping_parser.cr +++ b/src/parsers/mapping_parser.cr @@ -30,19 +30,35 @@ module GX::Parsers parser.on("-t", "--type TYPE", "Set filesystem type") do |type| add_args = add_args.merge({type: type}) end - parser.on("-n", "--name", "Set mapping name") do |name| add_args = add_args.merge({name: name}) end - - parser.on("-p", "--path", "Set mapping encrypted path") do |path| - add_args = add_args.merge({path: path}) + parser.on("--remote-user USER", "Set SSH user") do |user| + add_args = add_args.merge({remote_user: user}) end + parser.on("--remote-host HOST", "Set SSH host") do |host| + add_args = add_args.merge({remote_host: host}) + end + parser.on("--source-path PATH", "Set remote path") do |path| + add_args = add_args.merge({remote_path: path}) + end + parser.separator(Utils.help_line(breadcrumbs + "create")) end parser.on("edit", "Edit configuration") do |_| config.mode = Types::Mode::MappingEdit + + parser.on("--remote-user USER", "Set SSH user") do |user| + add_args = add_args.merge({remote_user: user}) + end + parser.on("--remote-host HOST", "Set SSH host") do |host| + add_args = add_args.merge({remote_host: host}) + end + parser.on("--source-path PATH", "Set remote path") do |path| + add_args = add_args.merge({remote_path: path}) + end + parser.separator(Utils.help_line(breadcrumbs + "edit")) # abort("FIXME: Not implemented") end -- 2.45.3 From 8f145189c0bc7bd6860f45ddce2d176042710b2a Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:29 +0100 Subject: [PATCH 11/53] fix: run ameba --fix on root_parser.cr --- src/parsers/root_parser.cr | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/parsers/root_parser.cr b/src/parsers/root_parser.cr index 70ac5a5..c3895dd 100644 --- a/src/parsers/root_parser.cr +++ b/src/parsers/root_parser.cr @@ -21,24 +21,24 @@ module GX::Parsers config.path = path end - parser.on("-v", "--verbose", "Set more verbosity") do |flag| + parser.on("-v", "--verbose", "Set more verbosity") do |_| Log.info { "Verbosity enabled" } config.verbose = true end - parser.on("-o", "--open", "Automatically open directory after mount") do |flag| + parser.on("-o", "--open", "Automatically open directory after mount") do |_| Log.info { "Auto-open enabled" } config.auto_open = true end - parser.on("--version", "Show version") do |flag| + parser.on("--version", "Show version") do |_| config.mode = Types::Mode::GlobalVersion end - parser.on("-h", "--help", "Show this help") do |flag| + parser.on("-h", "--help", "Show this help") do |_| config.mode = Types::Mode::GlobalHelp config.help_options = Parsers::Options::HelpOptions.new - config.help_options.try { |opts| opts.parser_snapshot = parser.dup } + config.help_options.try(&.parser_snapshot=(parser.dup)) end parser.separator("\nGlobal commands:") @@ -46,7 +46,7 @@ module GX::Parsers parser.on("config", "Manage configuration file") do config.mode = Types::Mode::GlobalHelp config.help_options = Parsers::Options::HelpOptions.new - config.help_options.try { |opts| opts.parser_snapshot = parser.dup } + config.help_options.try(&.parser_snapshot=(parser.dup)) # config.command = Commands::Config.new(config) Parsers::ConfigParser.new.build(parser, breadcrumbs, config) @@ -59,7 +59,7 @@ module GX::Parsers parser.on("mapping", "Manage mappings") do config.mode = Types::Mode::GlobalHelp config.help_options = Parsers::Options::HelpOptions.new - config.help_options.try { |opts| opts.parser_snapshot = parser.dup } + config.help_options.try(&.parser_snapshot=(parser.dup)) Parsers::MappingParser.new.build(parser, breadcrumbs, config) end -- 2.45.3 From be8980b74caf86078a21e06b28c1d8014dd55869 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 23 Jan 2024 23:48:29 +0100 Subject: [PATCH 12/53] fix: run ameba --fix on parser_lines.cr --- src/utils/parser_lines.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/parser_lines.cr b/src/utils/parser_lines.cr index dacd71f..4d9039e 100644 --- a/src/utils/parser_lines.cr +++ b/src/utils/parser_lines.cr @@ -3,7 +3,7 @@ require "./breadcrumbs" module GX::Utils def self.usage_line(breadcrumbs : BreadCrumbs, description : String, has_commands : Bool = false) [ - "Usage: #{breadcrumbs.to_s}#{has_commands ? " [commands]" : ""} [options]", + "Usage: #{breadcrumbs}#{has_commands ? " [commands]" : ""} [options]", "", description, "", @@ -12,6 +12,6 @@ module GX::Utils end def self.help_line(breadcrumbs : BreadCrumbs) - "\nRun '#{breadcrumbs.to_s} COMMAND --help' for more information on a command." + "\nRun '#{breadcrumbs} COMMAND --help' for more information on a command." end end -- 2.45.3 From 1a5c2cd223785ee7f0d120d23e92066fd43b5c98 Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 24 Jan 2024 00:06:28 +0100 Subject: [PATCH 13/53] feat: prepare (empty) files for completion and sample config --- static/completion.zsh | 0 static/sample.mfm.yaml | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 static/completion.zsh create mode 100644 static/sample.mfm.yaml diff --git a/static/completion.zsh b/static/completion.zsh new file mode 100644 index 0000000..e69de29 diff --git a/static/sample.mfm.yaml b/static/sample.mfm.yaml new file mode 100644 index 0000000..8eaa2b5 --- /dev/null +++ b/static/sample.mfm.yaml @@ -0,0 +1,32 @@ +--- +version: 1 + +global: + mount_point_base: "{{env.HOME}}/mnt" + +filesystems: + ## + ## Sample configuration for encrypted vault (gocryptfs) + ## + # - type: gocryptfs + # name: "Credential Vault" + # encrypted_path: "{{env.HOME}}/Documents/Credential.Vault" + # + ## + ## Sample configuration remote SSH directory (sshfs) + ## + # - type: sshfs + # name: "Remote SSH server" + # remote_host: ssh.example.com + # remote_user: "{{env.USER}}" + # remote_path: "/home/{{env.USER}}" + # remote_port: 443 + # + ## + ## Sample configuration for remote HTTP directory (httpdirfs) + ## + - type: httpdirfs + name: "Debian Repository" + url: "http://ftp.debian.org/debian/" + # mount_point: "{{env.HOME}}/another.dir" +# -- 2.45.3 From bb5941a86aea34a01dc52996fe7344ffab3416a5 Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 24 Jan 2024 00:06:52 +0100 Subject: [PATCH 14/53] fix: remove useless FIXME comments --- src/commands/global_config.cr | 2 +- src/commands/global_help.cr | 2 +- src/commands/mapping_mount.cr | 2 +- src/commands/mapping_umount.cr | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/global_config.cr b/src/commands/global_config.cr index c369556..b3ff036 100644 --- a/src/commands/global_config.cr +++ b/src/commands/global_config.cr @@ -2,7 +2,7 @@ require "./abstract_command" module GX::Commands class GlobalConfig < AbstractCommand - def initialize(config : GX::Config) # FIXME + def initialize(config : GX::Config) end def execute diff --git a/src/commands/global_help.cr b/src/commands/global_help.cr index 78f1616..794ec2e 100644 --- a/src/commands/global_help.cr +++ b/src/commands/global_help.cr @@ -2,7 +2,7 @@ require "./abstract_command" module GX::Commands class GlobalHelp < AbstractCommand - def initialize(@config : GX::Config) # FIXME + def initialize(@config : GX::Config) end def execute diff --git a/src/commands/mapping_mount.cr b/src/commands/mapping_mount.cr index db81351..a750c7a 100644 --- a/src/commands/mapping_mount.cr +++ b/src/commands/mapping_mount.cr @@ -5,7 +5,7 @@ module GX::Commands class MappingMount < AbstractCommand @file_system_manager : FileSystemManager - def initialize(@config : GX::Config) # FIXME + def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file @file_system_manager = FileSystemManager.new(@config) diff --git a/src/commands/mapping_umount.cr b/src/commands/mapping_umount.cr index dc61f1d..11dd92c 100644 --- a/src/commands/mapping_umount.cr +++ b/src/commands/mapping_umount.cr @@ -5,7 +5,7 @@ module GX::Commands class MappingUmount < AbstractCommand @file_system_manager : FileSystemManager - def initialize(@config : GX::Config) # FIXME + def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file @file_system_manager = FileSystemManager.new(@config) -- 2.45.3 From 91f2e7a5548c086e01ec8823a4b3750a5691251c Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 24 Jan 2024 00:07:29 +0100 Subject: [PATCH 15/53] fix: update code_preloader ignore list --- .code_preloader.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.code_preloader.yml b/.code_preloader.yml index 97920cc..3e94732 100644 --- a/.code_preloader.yml +++ b/.code_preloader.yml @@ -8,15 +8,20 @@ # List of patterns to ignore during preloading ignore_list: - - ^\.git/ - - ^lib.* - - ^doc/ - ^bin/ + - ^\.code_preloader.yml + - ^doc/ + - ^\.drone.yml + - ^\.git/ + - ^\.gitattributes + - ^\.gitignore + - ^lib.* + - ^LICENSES/ - ^_prompts/ - ^\.reuse/ - - ^LICENSES/ - - ^\.vagrant/ - ^scripts/ + - ^\.tool-versions + - ^\.vagrant/ # Path to the output file (if null, output to STDOUT) output_path: null -- 2.45.3 From cb99019be5d12124c2e15fb33d0292f5df1a36ab Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 24 Jan 2024 00:20:28 +0100 Subject: [PATCH 16/53] fix: add missing cli options for mapping command --- src/parsers/mapping_parser.cr | 59 +++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/src/parsers/mapping_parser.cr b/src/parsers/mapping_parser.cr index 60b2d7a..77b25f3 100644 --- a/src/parsers/mapping_parser.cr +++ b/src/parsers/mapping_parser.cr @@ -5,8 +5,10 @@ module GX::Parsers class MappingParser < AbstractParser def build(parser, ancestors, config) breadcrumbs = ancestors + "mapping" - add_args = {name: "", path: ""} + create_args = {name: "", path: ""} delete_args = {name: ""} + mount_args = {name: ""} + umount_args = {name: ""} parser.banner = Utils.usage_line( breadcrumbs, @@ -28,19 +30,30 @@ module GX::Parsers parser.separator("\nCreate options") parser.on("-t", "--type TYPE", "Set filesystem type") do |type| - add_args = add_args.merge({type: type}) + create_args = create_args.merge({type: type}) end parser.on("-n", "--name", "Set mapping name") do |name| - add_args = add_args.merge({name: name}) + create_args = create_args.merge({name: name}) end - parser.on("--remote-user USER", "Set SSH user") do |user| - add_args = add_args.merge({remote_user: user}) + + # Filesystem specific + parser.on("--encrypted-path PATH", "Set encrypted path (for gocryptfs)") do |path| + encrypted_path = path end - parser.on("--remote-host HOST", "Set SSH host") do |host| - add_args = add_args.merge({remote_host: host}) + parser.on("--remote-user USER", "Set SSH user (for sshfs)") do |user| + create_args = create_args.merge({remote_user: user}) end - parser.on("--source-path PATH", "Set remote path") do |path| - add_args = add_args.merge({remote_path: path}) + parser.on("--remote-host HOST", "Set SSH host (for sshfs)") do |host| + create_args = create_args.merge({remote_host: host}) + end + parser.on("--source-path PATH", "Set remote path (for sshfs)") do |path| + create_args = create_args.merge({remote_path: path}) + end + parser.on("--remote-port PORT", "Set SSH port (for sshfs)") do |port| + create_args = create_args.merge({remote_port: port}) + end + parser.on("--url URL", "Set URL (for httpdirfs)") do |url| + create_args = create_args.merge({url: url}) end parser.separator(Utils.help_line(breadcrumbs + "create")) @@ -50,13 +63,13 @@ module GX::Parsers config.mode = Types::Mode::MappingEdit parser.on("--remote-user USER", "Set SSH user") do |user| - add_args = add_args.merge({remote_user: user}) + create_args = create_args.merge({remote_user: user}) end parser.on("--remote-host HOST", "Set SSH host") do |host| - add_args = add_args.merge({remote_host: host}) + create_args = create_args.merge({remote_host: host}) end parser.on("--source-path PATH", "Set remote path") do |path| - add_args = add_args.merge({remote_path: path}) + create_args = create_args.merge({remote_path: path}) end parser.separator(Utils.help_line(breadcrumbs + "edit")) @@ -65,21 +78,35 @@ module GX::Parsers parser.on("mount", "Mount mapping") do |_| config.mode = Types::Mode::MappingMount + + parser.banner = Utils.usage_line(breadcrumbs + "mount", "mount mapping", true) + parser.separator("\nMount options") + + parser.on("-n", "--name", "Set mapping name") do |name| + mount_args = mount_args.merge({name: name}) + end + parser.separator(Utils.help_line(breadcrumbs + "mount")) - # abort("FIXME: Not implemented") end parser.on("umount", "Umount mapping") do |_| config.mode = Types::Mode::MappingUmount + + parser.banner = Utils.usage_line(breadcrumbs + "umount", "umount mapping", true) + parser.separator("\nUmount options") + + parser.on("-n", "--name", "Set mapping name") do |name| + umount_args = umount_args.merge({name: name}) + end + parser.separator(Utils.help_line(breadcrumbs + "umount")) - # abort("FIXME: Not implemented") end parser.on("delete", "Delete mapping") do config.mode = Types::Mode::MappingDelete - parser.banner = Utils.usage_line(breadcrumbs + "delete", "Delete mapping", true) - parser.separator("\nDelete options") + parser.banner = Utils.usage_line(breadcrumbs + "delete", "delete mapping", true) + parser.separator("\ndelete options") parser.on("-n", "--name", "Set mapping name") do |name| delete_args = delete_args.merge({name: name}) -- 2.45.3 From 1f5a2f33ecac757b43b7a643fcf0fcf3db85c22c Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 24 Jan 2024 00:28:46 +0100 Subject: [PATCH 17/53] fix: follow the crystal way for to_s --- src/utils/breadcrumbs.cr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/breadcrumbs.cr b/src/utils/breadcrumbs.cr index 89c54e9..f12c5f8 100644 --- a/src/utils/breadcrumbs.cr +++ b/src/utils/breadcrumbs.cr @@ -4,12 +4,12 @@ module GX::Utils @ancestors = base end - def +(elem : String) - b = BreadCrumbs.new(@ancestors + [elem]) + def +(other : String) + BreadCrumbs.new(@ancestors + [other]) end - def to_s - @ancestors.join(" ") + def to_s(io : IO) + io << @ancestors.join(" ") end def to_a -- 2.45.3 From 59ab4ce2728e5e75b9ab33f1f891be8138fb94a8 Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 24 Jan 2024 01:25:44 +0100 Subject: [PATCH 18/53] fix: change binary name --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f0c5bb8..f1faf70 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ test: install: install \ -m 755 \ - bin/code-preloader \ + bin/mfm \ $(PREFIX)/bin .PHONY: spec test build all prepare install -- 2.45.3 From 92aaf5f0b5b0ebaa8db615f6188a0e3072968e56 Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 24 Jan 2024 11:08:16 +0100 Subject: [PATCH 19/53] fix: remove useless comment --- src/parsers/mapping_parser.cr | 1 - 1 file changed, 1 deletion(-) diff --git a/src/parsers/mapping_parser.cr b/src/parsers/mapping_parser.cr index 77b25f3..d39b99f 100644 --- a/src/parsers/mapping_parser.cr +++ b/src/parsers/mapping_parser.cr @@ -20,7 +20,6 @@ module GX::Parsers parser.on("list", "List mappings") do config.mode = Types::Mode::MappingList parser.separator(Utils.help_line(breadcrumbs + "list")) - # abort("FIXME: Not implemented") end parser.on("create", "Create mapping") do -- 2.45.3 From 6ec7ae0ec7c8be99c0a7631b723a8ec12ea0ab87 Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 24 Jan 2024 14:13:29 +0100 Subject: [PATCH 20/53] fix: implement config init --- shard.lock | 4 ++++ shard.yml | 3 +++ src/commands/config_init.cr | 30 ++++++++++++++++++++++++++---- src/file_storage.cr | 8 ++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 src/file_storage.cr diff --git a/shard.lock b/shard.lock index e19d81c..216e1db 100644 --- a/shard.lock +++ b/shard.lock @@ -4,6 +4,10 @@ shards: git: https://github.com/crystal-ameba/ameba.git version: 1.6.1 + baked_file_system: + git: https://github.com/schovi/baked_file_system.git + version: 0.10.0 + crinja: git: https://github.com/straight-shoota/crinja.git version: 0.8.1 diff --git a/shard.yml b/shard.yml index 3b29118..d65fad5 100644 --- a/shard.yml +++ b/shard.yml @@ -26,6 +26,9 @@ dependencies: github: hugopl/version_from_shard tablo: github: hutou/tablo + baked_file_system: + github: schovi/baked_file_system + version: 0.10.0 development_dependencies: ameba: diff --git a/src/commands/config_init.cr b/src/commands/config_init.cr index 2171d39..07e5eb8 100644 --- a/src/commands/config_init.cr +++ b/src/commands/config_init.cr @@ -1,14 +1,36 @@ require "./abstract_command" +require "../file_storage" module GX::Commands class ConfigInit < AbstractCommand - def initialize(config : GX::Config) # FIXME + def initialize(@config : GX::Config) end def execute - puts "FIXME: detect if config is present" - puts "FIXME: compute config path (either default, or from command line)" - puts "FIXME: create config file from default if needed" + config_dir = File.join(@config.home_dir, ".config", "mfm") + config_file_path = File.join(config_dir, "config.yml") + + # 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." + return + end + + puts "Creating initial configuration file at #{config_file_path}" + + # Ensure the configuration directory exists + FileUtils.mkdir_p(config_dir) + + # Read the default configuration content from the baked file storage + default_config_content = FileStorage.get("sample.mfm.yaml") + + # Write the default configuration to the target path + File.write(config_file_path, default_config_content) + + puts "Configuration file created successfully." + rescue ex + STDERR.puts "Error creating the configuration file: #{ex.message}" + exit(1) end def self.handles_mode diff --git a/src/file_storage.cr b/src/file_storage.cr new file mode 100644 index 0000000..dd01b59 --- /dev/null +++ b/src/file_storage.cr @@ -0,0 +1,8 @@ +require "baked_file_system" + +class FileStorage + extend BakedFileSystem + + bake_folder "../static" +end + -- 2.45.3 From 0e2ddde0819f87cb63f33e2cffc819d6be11c6e5 Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 24 Jan 2024 14:15:42 +0100 Subject: [PATCH 21/53] doc: improve build instructions --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 254cb91..d143759 100644 --- a/README.md +++ b/README.md @@ -44,18 +44,23 @@ To build from source, you'll also need: For Debian/Ubuntu you can use the following command: ```shell-session -$ sudo apt-get update && sudo apt-get install libpcre3-dev libevent-2.1-dev +$ sudo apt-get update && sudo apt-get install libpcre3-dev libevent-2.1-dev make ``` ## Installation ### 1. From Source -1. Clone or download the source code. -2. Navigate to the source directory. -3. Run `shards install` to fetch dependencies. -4. Compile using `shards build`. -5. The compiled binary will be in the `bin` directory. +To get started with MFM, ensure that you have the prerequisites installed on your system (see above). + +Then follow these steps to install: + + git clone https://code.apps.glenux.net/glenux/mfm + cd mfm + make prepare + make build + sudo make install # either to install system-wide + make install PREFIX=$HOME/.local # or to install as a user ### 2. Binary Download -- 2.45.3 From 26510531e787645047ad6ca9de10a8c5724f94bd Mon Sep 17 00:00:00 2001 From: Glenn Date: Mon, 12 Feb 2024 11:53:49 +0100 Subject: [PATCH 22/53] doc: add stupid comment for demo --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d143759..4186a45 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ > version of our project, please visit our primary repository at: > . + + # Minimalist Fuse Manager (MFM) MFM is a Crystal-lang CLI designed to streamline the management of various FUSE filesystems, such as sshfs, gocryptfs, httpdirfs, and more. Through its user-friendly interface, users can effortlessly mount and unmount filesystems, get real-time filesystem status, and handle errors proficiently. -- 2.45.3 From 68934c3be85f9fb6d095393c353ce95403b6775d Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 4 Aug 2024 22:56:01 +0200 Subject: [PATCH 23/53] fix: disable useless GlobalMapping action --- src/commands/global_mapping.cr | 16 ---------------- src/types/modes.cr | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 src/commands/global_mapping.cr diff --git a/src/commands/global_mapping.cr b/src/commands/global_mapping.cr deleted file mode 100644 index 0c61b95..0000000 --- a/src/commands/global_mapping.cr +++ /dev/null @@ -1,16 +0,0 @@ -require "./abstract_command" - -module GX::Commands - class GlobalMapping < AbstractCommand - def initialize(config : GX::Config) # FIXME - end - - def execute - # FIXME: implement - end - - def self.handles_mode - GX::Types::Mode::GlobalMapping - end - end -end diff --git a/src/types/modes.cr b/src/types/modes.cr index 6498f89..810a8f7 100644 --- a/src/types/modes.cr +++ b/src/types/modes.cr @@ -7,7 +7,7 @@ module GX::Types GlobalCompletion GlobalTui GlobalConfig - GlobalMapping + # GlobalMapping ConfigInit -- 2.45.3 From 65fe1bf0b9d23adb9fd19c4369e1875aa0c73dd9 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 4 Aug 2024 22:57:09 +0200 Subject: [PATCH 24/53] refactor: remove useless code refering to interactive mode --- src/parsers/root_parser.cr | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/parsers/root_parser.cr b/src/parsers/root_parser.cr index c3895dd..b190985 100644 --- a/src/parsers/root_parser.cr +++ b/src/parsers/root_parser.cr @@ -64,10 +64,6 @@ module GX::Parsers Parsers::MappingParser.new.build(parser, breadcrumbs, config) end - # parser.on("interactive", "Interactive mapping mount/umount") do - # abort("FIXME: Not implemented") - # end - parser.on("completion", "Manage completion") do config.mode = Types::Mode::GlobalCompletion Parsers::CompletionParser.new.build(parser, breadcrumbs, config) -- 2.45.3 From df89dd3dfa18c6a74309564d1fb73a0d87e257f6 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 4 Aug 2024 22:58:09 +0200 Subject: [PATCH 25/53] feat: start implementing MappingCreate --- src/commands/mapping_create.cr | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index 1e3ec6f..8b8999f 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -2,11 +2,15 @@ require "./abstract_command" module GX::Commands class MappingCreate < AbstractCommand - def initialize(config : GX::Config) # FIXME + 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!" end def self.handles_mode -- 2.45.3 From c3217a75e3d6f0c1be7c69731e2d1e21b47e96f2 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 4 Aug 2024 22:58:40 +0200 Subject: [PATCH 26/53] feat: start adding support for mappings with encrypted paths --- src/parsers/mapping_parser.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parsers/mapping_parser.cr b/src/parsers/mapping_parser.cr index d39b99f..077a811 100644 --- a/src/parsers/mapping_parser.cr +++ b/src/parsers/mapping_parser.cr @@ -37,7 +37,7 @@ module GX::Parsers # Filesystem specific parser.on("--encrypted-path PATH", "Set encrypted path (for gocryptfs)") do |path| - encrypted_path = path + create_args = create_args.merge({encrypted_path: path}) end parser.on("--remote-user USER", "Set SSH user (for sshfs)") do |user| create_args = create_args.merge({remote_user: user}) -- 2.45.3 From c270df01e7e53ac86d3e1b8e1fae20cb19d0f745 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 4 Aug 2024 23:50:42 +0200 Subject: [PATCH 27/53] refactor(file_system_manager): extract fzf display as two functions --- src/file_system_manager.cr | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/file_system_manager.cr b/src/file_system_manager.cr index 9dc003c..8b8c97c 100644 --- a/src/file_system_manager.cr +++ b/src/file_system_manager.cr @@ -88,7 +88,7 @@ module GX config_root.filesystems end - def choose_filesystem + def choose_filesystem : GX::Models::AbstractFilesystemConfig? names_display = {} of String => NamedTuple( filesystem: Models::AbstractFilesystemConfig, ansi_name: String) @@ -97,17 +97,8 @@ module GX return if config_root.nil? config_root.filesystems.each do |filesystem| - fs_str = filesystem.type.ljust(12, ' ') - - suffix = "" - suffix_ansi = "" - if filesystem.mounted? - suffix = "[open]" - suffix_ansi = "[#{"open".colorize(:green)}]" - end - - result_name = "#{fs_str} #{filesystem.name} #{suffix}".strip - ansi_name = "#{fs_str.colorize(:dark_gray)} #{filesystem.name} #{suffix_ansi}".strip + result_name = _fzf_plain_name(filesystem) + ansi_name = _fzf_ansi_name(filesystem) names_display[result_name] = { filesystem: filesystem, @@ -128,12 +119,18 @@ module GX selected_filesystem end - private def generate_display_name(filesystem : Models::AbstractFilesystemConfig) : String + private def _fzf_plain_name(filesystem : Models::AbstractFilesystemConfig) : String fs_str = filesystem.type.ljust(12, ' ') suffix = filesystem.mounted? ? "[open]" : "" "#{fs_str} #{filesystem.name} #{suffix}".strip end + private def _fzf_ansi_name(filesystem : Models::AbstractFilesystemConfig) : String + fs_str = filesystem.type.ljust(12, ' ').colorize(:dark_gray) + suffix = filesystem.mounted? ? "[#{"open".colorize(:green)}]" : "" + "#{fs_str} #{filesystem.name} #{suffix}".strip + end + private def graphical_environment? if ENV["DISPLAY"]? || ENV["WAYLAND_DISPLAY"]? return true -- 2.45.3 From 9e68d3bf70ec593ebb88dd44f9ddf36eeb80262c Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 6 Oct 2024 14:30:41 +0200 Subject: [PATCH 28/53] feat: add spec for commands/mapping --- spec/commands/mapping_create_spec.cr | 7 +++++++ spec/commands/mapping_edit_spec.cr | 7 +++++++ spec/commands/mapping_list_spec.cr | 7 +++++++ 3 files changed, 21 insertions(+) create mode 100644 spec/commands/mapping_create_spec.cr create mode 100644 spec/commands/mapping_edit_spec.cr create mode 100644 spec/commands/mapping_list_spec.cr diff --git a/spec/commands/mapping_create_spec.cr b/spec/commands/mapping_create_spec.cr new file mode 100644 index 0000000..42c58af --- /dev/null +++ b/spec/commands/mapping_create_spec.cr @@ -0,0 +1,7 @@ +require "../spec_helper" +require "../../src/commands/mapping_create" + +describe GX::Commands::MappingCreate do + context "Initialization" do + end +end diff --git a/spec/commands/mapping_edit_spec.cr b/spec/commands/mapping_edit_spec.cr new file mode 100644 index 0000000..a042c80 --- /dev/null +++ b/spec/commands/mapping_edit_spec.cr @@ -0,0 +1,7 @@ +require "../spec_helper" +require "../../src/commands/mapping_edit" + +describe GX::Commands::MappingEdit do + context "Initialization" do + end +end diff --git a/spec/commands/mapping_list_spec.cr b/spec/commands/mapping_list_spec.cr new file mode 100644 index 0000000..008862a --- /dev/null +++ b/spec/commands/mapping_list_spec.cr @@ -0,0 +1,7 @@ +require "../spec_helper" +require "../../src/commands/mapping_list" + +describe GX::Commands::MappingList do + context "Initialization" do + end +end -- 2.45.3 From c541a2556d45f653727f6c555866e267e003e4d5 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 13 Oct 2024 15:03:09 +0200 Subject: [PATCH 29/53] fix: breadcrumb spec for string conversion --- spec/utils/breadcrumbs_spec.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/utils/breadcrumbs_spec.cr b/spec/utils/breadcrumbs_spec.cr index deec943..1d97594 100644 --- a/spec/utils/breadcrumbs_spec.cr +++ b/spec/utils/breadcrumbs_spec.cr @@ -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 -- 2.45.3 From 07f2275a41e92ccc5cc4b3663395a5174e1e45d6 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 13 Oct 2024 15:03:33 +0200 Subject: [PATCH 30/53] feat: add new spec files --- spec/parsers/completion_parser_spec.cr | 0 spec/parsers/config_parser_spec.cr | 68 ++++++++++++++++++++++++++ spec/parsers/mapping_parser_spec.cr | 0 spec/parsers/root_parser_spec.cr | 0 4 files changed, 68 insertions(+) create mode 100644 spec/parsers/completion_parser_spec.cr create mode 100644 spec/parsers/config_parser_spec.cr create mode 100644 spec/parsers/mapping_parser_spec.cr create mode 100644 spec/parsers/root_parser_spec.cr diff --git a/spec/parsers/completion_parser_spec.cr b/spec/parsers/completion_parser_spec.cr new file mode 100644 index 0000000..e69de29 diff --git a/spec/parsers/config_parser_spec.cr b/spec/parsers/config_parser_spec.cr new file mode 100644 index 0000000..ac9deee --- /dev/null +++ b/spec/parsers/config_parser_spec.cr @@ -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 diff --git a/spec/parsers/mapping_parser_spec.cr b/spec/parsers/mapping_parser_spec.cr new file mode 100644 index 0000000..e69de29 diff --git a/spec/parsers/root_parser_spec.cr b/spec/parsers/root_parser_spec.cr new file mode 100644 index 0000000..e69de29 -- 2.45.3 From 44b5daf5c79c48afb907d7964ffbf6ffa19ddaa5 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 13 Oct 2024 15:06:01 +0200 Subject: [PATCH 31/53] fix: add missing parameter to --path option --- src/parsers/config_parser.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parsers/config_parser.cr b/src/parsers/config_parser.cr index f1dfa3f..e3ffc05 100644 --- a/src/parsers/config_parser.cr +++ b/src/parsers/config_parser.cr @@ -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 -- 2.45.3 From da0cf858a4c335dad175d08dede425ebad9eaa8d Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 25 Oct 2024 17:27:36 +0200 Subject: [PATCH 32/53] refactor: Replace root_config initialization with config.root usage --- src/commands/mapping_create.cr | 42 +++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index 8b8999f..0d22953 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -5,12 +5,48 @@ 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!" + # 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 -- 2.45.3 From d39c7117a4ec7ecfd5a1dcbd2656888e5a68fc77 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 25 Oct 2024 12:30:44 +0200 Subject: [PATCH 33/53] refactor: Move mapping_create_options property to the correct position --- src/config.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.cr b/src/config.cr index d375cce..12f6b8c 100644 --- a/src/config.cr +++ b/src/config.cr @@ -37,6 +37,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"]? -- 2.45.3 From bfbc9bb3019c47e9a918e04d366db913354abbc4 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 25 Oct 2024 13:36:08 +0200 Subject: [PATCH 34/53] fix: Add FIXME comment to verify filesystem validity in mapping_create command --- src/commands/mapping_create.cr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index 0d22953..e7557ed 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -8,6 +8,8 @@ module GX::Commands end def execute + # 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 -- 2.45.3 From e27495eecf64423e44f9bc864e89d51ecc767d6c Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 25 Oct 2024 17:30:45 +0200 Subject: [PATCH 35/53] fix: update param in code_preloader --- .code_preloader.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.code_preloader.yml b/.code_preloader.yml index 3e94732..bcfda9b 100644 --- a/.code_preloader.yml +++ b/.code_preloader.yml @@ -7,7 +7,7 @@ # - "path/to/repo2" # List of patterns to ignore during preloading -ignore_list: +exclude_list: - ^bin/ - ^\.code_preloader.yml - ^doc/ -- 2.45.3 From 6d15d331d895c2dd034094a52571adbc455c6d9b Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 25 Oct 2024 17:31:29 +0200 Subject: [PATCH 36/53] fix: git must ignore .aider and .env --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ccd3fc2..33ba6d4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ .vagrant bin lib +.aider* +.env -- 2.45.3 From ced3168471c0c3cc0edd63270ae373eadf456c44 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 25 Oct 2024 17:33:07 +0200 Subject: [PATCH 37/53] STASH --- src/commands/config_init.cr | 10 ++++++++++ src/commands/mapping_mount.cr | 1 - src/config.cr | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/commands/config_init.cr b/src/commands/config_init.cr index 07e5eb8..e4fe50e 100644 --- a/src/commands/config_init.cr +++ b/src/commands/config_init.cr @@ -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." diff --git a/src/commands/mapping_mount.cr b/src/commands/mapping_mount.cr index a750c7a..8dcadb4 100644 --- a/src/commands/mapping_mount.cr +++ b/src/commands/mapping_mount.cr @@ -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 diff --git a/src/config.cr b/src/config.cr index 12f6b8c..d56ac18 100644 --- a/src/config.cr +++ b/src/config.cr @@ -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 -- 2.45.3 From 8dc7e297580f6170f62dec31101fc8ad40d50146 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 27 Oct 2024 20:41:35 +0100 Subject: [PATCH 38/53] fix: add missing SPDX headers to files --- Vagrantfile | 5 +++++ src/command_factory.cr | 5 +++++ src/commands.cr | 5 +++++ src/commands/abstract_command.cr | 5 +++++ src/commands/config_init.cr | 5 +++++ src/commands/global_completion.cr | 5 +++++ src/commands/global_config.cr | 5 +++++ src/commands/global_help.cr | 5 +++++ src/commands/global_tui.cr | 5 +++++ src/commands/global_version.cr | 5 +++++ src/commands/mapping_create.cr | 5 +++++ src/commands/mapping_delete.cr | 5 +++++ src/commands/mapping_edit.cr | 5 +++++ src/commands/mapping_list.cr | 5 +++++ src/commands/mapping_mount.cr | 5 +++++ src/commands/mapping_umount.cr | 5 +++++ src/file_storage.cr | 5 +++++ src/file_system_manager.cr | 5 +++++ src/models/concerns/base.cr | 5 +++++ src/parsers/base.cr | 5 +++++ src/parsers/completion_parser.cr | 5 +++++ src/parsers/config_parser.cr | 5 +++++ src/parsers/mapping_parser.cr | 5 +++++ src/parsers/options/config_init_options.cr | 5 +++++ src/parsers/options/config_options.cr | 5 +++++ src/parsers/options/help_options.cr | 5 +++++ src/parsers/root_parser.cr | 5 +++++ src/types/modes.cr | 5 +++++ src/utils/breadcrumbs.cr | 5 +++++ src/utils/parser_lines.cr | 5 +++++ src/version.cr | 5 +++++ static/completion.bash | 4 ++++ static/completion.zsh | 6 ++++++ 33 files changed, 165 insertions(+) diff --git a/Vagrantfile b/Vagrantfile index 6ea27b7..9d805c0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + # frozen_string_literal: true # -*- mode: ruby -*- diff --git a/src/command_factory.cr b/src/command_factory.cr index c2d7e22..58ef721 100644 --- a/src/command_factory.cr +++ b/src/command_factory.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./commands" module GX diff --git a/src/commands.cr b/src/commands.cr index 034a066..646088a 100644 --- a/src/commands.cr +++ b/src/commands.cr @@ -1 +1,6 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./commands/*" diff --git a/src/commands/abstract_command.cr b/src/commands/abstract_command.cr index 7591f15..c6f8296 100644 --- a/src/commands/abstract_command.cr +++ b/src/commands/abstract_command.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "../config" module GX::Commands diff --git a/src/commands/config_init.cr b/src/commands/config_init.cr index e4fe50e..df2ecee 100644 --- a/src/commands/config_init.cr +++ b/src/commands/config_init.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" require "../file_storage" diff --git a/src/commands/global_completion.cr b/src/commands/global_completion.cr index 4549818..7451b49 100644 --- a/src/commands/global_completion.cr +++ b/src/commands/global_completion.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" module GX::Commands diff --git a/src/commands/global_config.cr b/src/commands/global_config.cr index b3ff036..4e617d3 100644 --- a/src/commands/global_config.cr +++ b/src/commands/global_config.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" module GX::Commands diff --git a/src/commands/global_help.cr b/src/commands/global_help.cr index 794ec2e..36b87da 100644 --- a/src/commands/global_help.cr +++ b/src/commands/global_help.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" module GX::Commands diff --git a/src/commands/global_tui.cr b/src/commands/global_tui.cr index 58f22ed..9b162dd 100644 --- a/src/commands/global_tui.cr +++ b/src/commands/global_tui.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" require "../file_system_manager" diff --git a/src/commands/global_version.cr b/src/commands/global_version.cr index 9cd6757..944f026 100644 --- a/src/commands/global_version.cr +++ b/src/commands/global_version.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" require "../config" diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index e7557ed..54170a0 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" module GX::Commands diff --git a/src/commands/mapping_delete.cr b/src/commands/mapping_delete.cr index bed0534..1849320 100644 --- a/src/commands/mapping_delete.cr +++ b/src/commands/mapping_delete.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" module GX::Commands diff --git a/src/commands/mapping_edit.cr b/src/commands/mapping_edit.cr index b0ef961..216cae9 100644 --- a/src/commands/mapping_edit.cr +++ b/src/commands/mapping_edit.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" module GX::Commands diff --git a/src/commands/mapping_list.cr b/src/commands/mapping_list.cr index 35cd299..3754edd 100644 --- a/src/commands/mapping_list.cr +++ b/src/commands/mapping_list.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" require "../file_system_manager" require "tablo" diff --git a/src/commands/mapping_mount.cr b/src/commands/mapping_mount.cr index 8dcadb4..9e896eb 100644 --- a/src/commands/mapping_mount.cr +++ b/src/commands/mapping_mount.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" require "../file_system_manager" diff --git a/src/commands/mapping_umount.cr b/src/commands/mapping_umount.cr index 11dd92c..77364c2 100644 --- a/src/commands/mapping_umount.cr +++ b/src/commands/mapping_umount.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./abstract_command" require "../file_system_manager" diff --git a/src/file_storage.cr b/src/file_storage.cr index dd01b59..20a9d7b 100644 --- a/src/file_storage.cr +++ b/src/file_storage.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "baked_file_system" class FileStorage diff --git a/src/file_system_manager.cr b/src/file_system_manager.cr index 8b8c97c..5281b7c 100644 --- a/src/file_system_manager.cr +++ b/src/file_system_manager.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + # require "./models/abstract_filesystem_config" require "./utils/fzf" diff --git a/src/models/concerns/base.cr b/src/models/concerns/base.cr index 219a456..99be687 100644 --- a/src/models/concerns/base.cr +++ b/src/models/concerns/base.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + module GX::Models::Concerns module Base def mounted? : Bool diff --git a/src/parsers/base.cr b/src/parsers/base.cr index 8f3573b..e934b7c 100644 --- a/src/parsers/base.cr +++ b/src/parsers/base.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + module GX::Parsers abstract class AbstractParser abstract def build(parser : OptionParser, ancestors : BreadCrumbs, config : Config) diff --git a/src/parsers/completion_parser.cr b/src/parsers/completion_parser.cr index 3a068f9..4a29920 100644 --- a/src/parsers/completion_parser.cr +++ b/src/parsers/completion_parser.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./base.cr" module GX::Parsers diff --git a/src/parsers/config_parser.cr b/src/parsers/config_parser.cr index e3ffc05..1999e8b 100644 --- a/src/parsers/config_parser.cr +++ b/src/parsers/config_parser.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./options/config_options" require "./options/config_init_options" require "./base" diff --git a/src/parsers/mapping_parser.cr b/src/parsers/mapping_parser.cr index 077a811..7c7365f 100644 --- a/src/parsers/mapping_parser.cr +++ b/src/parsers/mapping_parser.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./base.cr" require "../utils/parser_lines" diff --git a/src/parsers/options/config_init_options.cr b/src/parsers/options/config_init_options.cr index 97a31a3..d28065c 100644 --- a/src/parsers/options/config_init_options.cr +++ b/src/parsers/options/config_init_options.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "option_parser" module GX::Parsers::Options diff --git a/src/parsers/options/config_options.cr b/src/parsers/options/config_options.cr index 6cacac0..37b29b8 100644 --- a/src/parsers/options/config_options.cr +++ b/src/parsers/options/config_options.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "option_parser" module GX::Parsers::Options diff --git a/src/parsers/options/help_options.cr b/src/parsers/options/help_options.cr index e81fa2e..0a2b865 100644 --- a/src/parsers/options/help_options.cr +++ b/src/parsers/options/help_options.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "option_parser" module GX::Parsers::Options diff --git a/src/parsers/root_parser.cr b/src/parsers/root_parser.cr index b190985..7c9c908 100644 --- a/src/parsers/root_parser.cr +++ b/src/parsers/root_parser.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./base" require "./config_parser" require "./mapping_parser" diff --git a/src/types/modes.cr b/src/types/modes.cr index 810a8f7..69dbdc8 100644 --- a/src/types/modes.cr +++ b/src/types/modes.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + module GX::Types enum Mode None diff --git a/src/utils/breadcrumbs.cr b/src/utils/breadcrumbs.cr index f12c5f8..01f5833 100644 --- a/src/utils/breadcrumbs.cr +++ b/src/utils/breadcrumbs.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + module GX::Utils class BreadCrumbs def initialize(base : Array(String)) diff --git a/src/utils/parser_lines.cr b/src/utils/parser_lines.cr index 4d9039e..adee77e 100644 --- a/src/utils/parser_lines.cr +++ b/src/utils/parser_lines.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "./breadcrumbs" module GX::Utils diff --git a/src/version.cr b/src/version.cr index 0fd98ff..4adcdb2 100644 --- a/src/version.cr +++ b/src/version.cr @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + require "version_from_shard" module GX diff --git a/static/completion.bash b/static/completion.bash index d990879..cbede6a 100644 --- a/static/completion.bash +++ b/static/completion.bash @@ -1,4 +1,8 @@ #!/bin/bash +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland # mfm Bash completion script diff --git a/static/completion.zsh b/static/completion.zsh index e69de29..f57dc9d 100644 --- a/static/completion.zsh +++ b/static/completion.zsh @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + + -- 2.45.3 From 995ab4d49668b0973212a04d9561b8c7c61e9fb7 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 27 Oct 2024 20:45:01 +0100 Subject: [PATCH 39/53] feat: add format target into makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index f1faf70..f8e3b8a 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,9 @@ spec: test test: crystal spec --error-trace +format: + crystal tool format + install: install \ -m 755 \ -- 2.45.3 From 8b0d64ad86b5619c821794caf21086dc6565bd57 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 27 Oct 2024 20:47:24 +0100 Subject: [PATCH 40/53] fix: remove useless assignation in fzf --- src/utils/fzf.cr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/fzf.cr b/src/utils/fzf.cr index ff626f3..d3d8670 100644 --- a/src/utils/fzf.cr +++ b/src/utils/fzf.cr @@ -28,7 +28,8 @@ module GX::Utils exit(1) end - result = output.to_s.strip # .split.first? + # result + output.to_s.strip end end end -- 2.45.3 From 60a7356f8b9d108421342a2b28aae74ca12e3366 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 27 Oct 2024 21:36:23 +0100 Subject: [PATCH 41/53] fix: add better handling of exceptions (parsing, arguments, options, ...) --- src/cli.cr | 11 ++++++++++- src/config.cr | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cli.cr b/src/cli.cr index 4366d07..2498ee3 100644 --- a/src/cli.cr +++ b/src/cli.cr @@ -30,13 +30,22 @@ module GX Parsers::RootParser.new.build(parser, breadcrumbs, @config) end pparser.parse(args) + rescue e : OptionParser::MissingOption + STDERR.puts "ERROR: #{e.message}".colorize(:red) + exit(1) end def run command = CommandFactory.create_command(@config, @config.mode) abort("ERROR: unknown command for mode #{@config.mode}") if command.nil? - command.try &.execute + command.execute + rescue e : ArgumentError + STDERR.puts "ERROR: #{e.message}".colorize(:red) + exit(1) + rescue e : Exception + STDERR.puts "ERROR: #{e.message}".colorize(:red) + exit(1) end end end diff --git a/src/config.cr b/src/config.cr index d56ac18..dfba077 100644 --- a/src/config.cr +++ b/src/config.cr @@ -102,7 +102,12 @@ module GX file_data = File.read(config_path) file_patched = Crinja.render(file_data, {"env" => ENV.to_h}) - root = Models::RootConfig.from_yaml(file_patched) + begin + root = Models::RootConfig.from_yaml(file_patched) + rescue ex : YAML::ParseException + STDERR.puts "Error parsing configuration file: #{ex.message}".colorize(:red) + exit(1) + end mount_point_base_safe = root.global.mount_point_base raise Models::InvalidMountpointError.new("Invalid global mount point") if mount_point_base_safe.nil? -- 2.45.3 From ef4ca70eedb22b8186907fdfcc53abd0c513ce05 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 27 Oct 2024 21:59:57 +0100 Subject: [PATCH 42/53] fix: use ? suffit for boolean variables --- src/commands/global_tui.cr | 2 +- src/commands/mapping_mount.cr | 2 +- src/config.cr | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/global_tui.cr b/src/commands/global_tui.cr index 9b162dd..0b71acd 100644 --- a/src/commands/global_tui.cr +++ b/src/commands/global_tui.cr @@ -20,7 +20,7 @@ module GX::Commands filesystem = @file_system_manager.choose_filesystem raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? @file_system_manager.mount_or_umount(filesystem) - @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open + @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? end def self.handles_mode diff --git a/src/commands/mapping_mount.cr b/src/commands/mapping_mount.cr index 9e896eb..7f2a1af 100644 --- a/src/commands/mapping_mount.cr +++ b/src/commands/mapping_mount.cr @@ -20,7 +20,7 @@ module GX::Commands filesystem = @file_system_manager.choose_filesystem raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? filesystem.mount - @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open + @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? end def self.handles_mode diff --git a/src/config.cr b/src/config.cr index dfba077..78bbbcc 100644 --- a/src/config.cr +++ b/src/config.cr @@ -31,11 +31,11 @@ module GX getter home_dir : String getter root : Models::RootConfig? - property verbose : Bool + property? verbose : Bool property mode : Types::Mode property path : String? property args : AddArgs.class | DelArgs.class | NoArgs.class - property auto_open : Bool + property? auto_open : Bool # FIXME: refactor and remove these parts from here property help_options : Parsers::Options::HelpOptions? -- 2.45.3 From ad3af05032bfd3ab10e028d175dd5497125b65c7 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 27 Oct 2024 22:08:58 +0100 Subject: [PATCH 43/53] refactor: remove hardcoded filesystem testing --- src/commands/mapping_create.cr | 59 ++++++++----------- src/config.cr | 5 +- src/models/filesystem_factory.cr | 21 +++++++ src/models/gocryptfs_config.cr | 6 ++ src/models/httpdirfs_config.cr | 6 ++ src/models/sshfs_config.cr | 9 +++ src/parsers/mapping_parser.cr | 51 +++++++++++----- src/parsers/options/mapping_create_options.cr | 19 ++++++ src/parsers/options/mapping_delete_options.cr | 12 ++++ src/parsers/options/mapping_mount_options.cr | 12 ++++ src/parsers/options/mapping_umount_options.cr | 12 ++++ 11 files changed, 163 insertions(+), 49 deletions(-) create mode 100644 src/models/filesystem_factory.cr create mode 100644 src/parsers/options/mapping_create_options.cr create mode 100644 src/parsers/options/mapping_delete_options.cr create mode 100644 src/parsers/options/mapping_mount_options.cr create mode 100644 src/parsers/options/mapping_umount_options.cr diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index 54170a0..40dbaa7 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -13,51 +13,44 @@ module GX::Commands end def execute - # 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 + # Assuming mapping_create_options is passed to this command with necessary details + create_options = @config.mapping_create_options # Validate required arguments - if create_args[:name].empty? || create_args[:path].empty? - raise ArgumentError.new("Name and path are required to create a mapping.") + if create_options.nil? + raise ArgumentError.new("Mapping create options are required") + end + if create_options.name.nil? || create_options.name.try &.empty? + raise ArgumentError.new("Name is required to create a mapping.") + end + if create_options.type.nil? || create_options.type.try &.empty? + raise ArgumentError.new("Type is 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 + filesystem_config = GX::Models::FilesystemFactory.build(create_options) # Append the new filesystem config to the root config - @config.root.try &.filesystems << filesystem_config + @config.root.try do |root| + root.filesystems ||= [] of GX::Models::AbstractFilesystemConfig + root.filesystems << filesystem_config + root.file_system_manager.mount_or_umount(filesystem_config) + end - puts "Mapping '#{create_args[:name]}' created and added to configuration successfully." + puts "Mapping '#{create_options.name}' created and added to configuration successfully." end def self.handles_mode GX::Types::Mode::MappingCreate end + + + # validate create_options.PARAMETER and display error with description if + # missing + macro option_check(create_options, parameter, description) + if create_options.{{ parameter.id }}.nil? || create_options.{{ parameter.id }}.try &.empty? + raise ArgumentError.new("Parameter for " + {{description}} + " is required") + end + end end end diff --git a/src/config.cr b/src/config.cr index 78bbbcc..853e7cc 100644 --- a/src/config.cr +++ b/src/config.cr @@ -37,10 +37,11 @@ module GX property args : AddArgs.class | DelArgs.class | NoArgs.class property? auto_open : Bool - # FIXME: refactor and remove these parts from here - property help_options : Parsers::Options::HelpOptions? + # TODO: refactor and remove these parts from here property config_init_options : Parsers::Options::ConfigInitOptions? property config_options : Parsers::Options::ConfigOptions? + property help_options : Parsers::Options::HelpOptions? + property mapping_create_options : Parsers::Options::MappingCreateOptions? property mapping_create_options : Parsers::Options::MappingCreateOptions? def initialize diff --git a/src/models/filesystem_factory.cr b/src/models/filesystem_factory.cr new file mode 100644 index 0000000..9d43bf5 --- /dev/null +++ b/src/models/filesystem_factory.cr @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + +module GX::Models + class FilesystemFactory + def self.build(create_options) + case create_options.type + when "gocryptfs" + GoCryptFSConfig.new(create_options) + when "sshfs" + SshFSConfig.new(create_options) + when "httpdirfs" + HttpDirFSConfig.new(create_options) + else + raise ArgumentError.new("Unsupported mapping type: #{create_options.type}") + end + end + end +end diff --git a/src/models/gocryptfs_config.cr b/src/models/gocryptfs_config.cr index f6ea5b0..6e3b497 100644 --- a/src/models/gocryptfs_config.cr +++ b/src/models/gocryptfs_config.cr @@ -13,6 +13,11 @@ module GX::Models include Concerns::Base + def initialize(create_options) + @name = create_options.name.as(String) + @encrypted_path = create_options.encrypted_path.as(String) + end + def _mounted_prefix "#{encrypted_path}" end @@ -34,5 +39,6 @@ module GX::Models ) process.wait end + def self.name ; "gocryptfs" ; end end end diff --git a/src/models/httpdirfs_config.cr b/src/models/httpdirfs_config.cr index bcf0227..9b3f603 100644 --- a/src/models/httpdirfs_config.cr +++ b/src/models/httpdirfs_config.cr @@ -13,6 +13,11 @@ module GX::Models include Concerns::Base + def initialize(create_options) + @name = create_options.name.as(String) + @url = create_options.url.as(String) + end + def _mounted_prefix "httpdirfs" end @@ -34,5 +39,6 @@ module GX::Models ) process.wait end + def self.name ; "httpdirfs" ; end end end diff --git a/src/models/sshfs_config.cr b/src/models/sshfs_config.cr index 82b3538..08cf2b0 100644 --- a/src/models/sshfs_config.cr +++ b/src/models/sshfs_config.cr @@ -16,6 +16,14 @@ module GX::Models include Concerns::Base + def initialize(create_options) + @name = create_options.name.as(String) + @remote_user = create_options.remote_user.as(String) + @remote_host = create_options.remote_host.as(String) + @remote_path = create_options.remote_path.as(String) + @remote_port = create_options.remote_port.as(String) + end + def _mounted_prefix "#{@remote_user}@#{@remote_host}:#{@remote_path}" end @@ -41,5 +49,6 @@ module GX::Models ) process.wait end + def self.name ; "sshfs" ; end end end diff --git a/src/parsers/mapping_parser.cr b/src/parsers/mapping_parser.cr index 7c7365f..8c4a1d1 100644 --- a/src/parsers/mapping_parser.cr +++ b/src/parsers/mapping_parser.cr @@ -10,7 +10,6 @@ module GX::Parsers class MappingParser < AbstractParser def build(parser, ancestors, config) breadcrumbs = ancestors + "mapping" - create_args = {name: "", path: ""} delete_args = {name: ""} mount_args = {name: ""} umount_args = {name: ""} @@ -29,35 +28,53 @@ module GX::Parsers parser.on("create", "Create mapping") do config.mode = Types::Mode::MappingCreate - # pp parser + config.mode = Types::Mode::MappingCreate + config.mapping_create_options = Parsers::Options::MappingCreateOptions.new + parser.banner = Utils.usage_line(breadcrumbs + "create", "Create mapping", true) parser.separator("\nCreate options") parser.on("-t", "--type TYPE", "Set filesystem type") do |type| - create_args = create_args.merge({type: type}) + config.mapping_create_options.try do |opts| + opts.type = type + end end - parser.on("-n", "--name", "Set mapping name") do |name| - create_args = create_args.merge({name: name}) + parser.on("-n", "--name NAME", "Set mapping name") do |name| + config.mapping_create_options.try do |opts| + opts.name = name + end end # Filesystem specific parser.on("--encrypted-path PATH", "Set encrypted path (for gocryptfs)") do |path| - create_args = create_args.merge({encrypted_path: path}) + config.mapping_create_options.try do |opts| + opts.encrypted_path = path + end end parser.on("--remote-user USER", "Set SSH user (for sshfs)") do |user| - create_args = create_args.merge({remote_user: user}) + config.mapping_create_options.try do |opts| + opts.remote_user = user + end end parser.on("--remote-host HOST", "Set SSH host (for sshfs)") do |host| - create_args = create_args.merge({remote_host: host}) + config.mapping_create_options.try do |opts| + opts.remote_host = host + end end parser.on("--source-path PATH", "Set remote path (for sshfs)") do |path| - create_args = create_args.merge({remote_path: path}) + config.mapping_create_options.try do |opts| + opts.remote_path = path + end end parser.on("--remote-port PORT", "Set SSH port (for sshfs)") do |port| - create_args = create_args.merge({remote_port: port}) + config.mapping_create_options.try do |opts| + opts.remote_port = port + end end parser.on("--url URL", "Set URL (for httpdirfs)") do |url| - create_args = create_args.merge({url: url}) + config.mapping_create_options.try do |opts| + opts.url = url + end end parser.separator(Utils.help_line(breadcrumbs + "create")) @@ -67,13 +84,19 @@ module GX::Parsers config.mode = Types::Mode::MappingEdit parser.on("--remote-user USER", "Set SSH user") do |user| - create_args = create_args.merge({remote_user: user}) + config.mapping_create_options.try do |opts| + opts.remote_user = user + end end parser.on("--remote-host HOST", "Set SSH host") do |host| - create_args = create_args.merge({remote_host: host}) + config.mapping_create_options.try do |opts| + opts.remote_host = host + end end parser.on("--source-path PATH", "Set remote path") do |path| - create_args = create_args.merge({remote_path: path}) + config.mapping_create_options.try do |opts| + opts.remote_path = path + end end parser.separator(Utils.help_line(breadcrumbs + "edit")) diff --git a/src/parsers/options/mapping_create_options.cr b/src/parsers/options/mapping_create_options.cr new file mode 100644 index 0000000..1137777 --- /dev/null +++ b/src/parsers/options/mapping_create_options.cr @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + +require "option_parser" + +module GX::Parsers::Options + class MappingCreateOptions + property type : String? + property name : String? + property encrypted_path : String? + property remote_user : String? + property remote_host : String? + property remote_path : String? + property remote_port : String? + property url : String? + end +end diff --git a/src/parsers/options/mapping_delete_options.cr b/src/parsers/options/mapping_delete_options.cr new file mode 100644 index 0000000..c881f24 --- /dev/null +++ b/src/parsers/options/mapping_delete_options.cr @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + +require "option_parser" + +module GX::Parsers::Options + class MappingDeleteOptions + # Add your options here + end +end diff --git a/src/parsers/options/mapping_mount_options.cr b/src/parsers/options/mapping_mount_options.cr new file mode 100644 index 0000000..c5cf059 --- /dev/null +++ b/src/parsers/options/mapping_mount_options.cr @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + +require "option_parser" + +module GX::Parsers::Options + class MappingMountOptions + # Add your options here + end +end diff --git a/src/parsers/options/mapping_umount_options.cr b/src/parsers/options/mapping_umount_options.cr new file mode 100644 index 0000000..df948e9 --- /dev/null +++ b/src/parsers/options/mapping_umount_options.cr @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# SPDX-FileCopyrightText: 2024 Glenn Y. Rolland +# Copyright © 2024 Glenn Y. Rolland + +require "option_parser" + +module GX::Parsers::Options + class MappingUmountOptions + # Add your options here + end +end -- 2.45.3 From bc9aa7c0f9f229ff48cb9e0bb4805f357c8c779f Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 27 Oct 2024 22:09:47 +0100 Subject: [PATCH 44/53] feat: add tests for mapping commands (broken) --- spec/commands/mapping_create_spec.cr | 6 ++ spec/commands/mapping_edit_spec.cr | 5 ++ spec/commands/mapping_list_spec.cr | 101 +++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/spec/commands/mapping_create_spec.cr b/spec/commands/mapping_create_spec.cr index 42c58af..e03e191 100644 --- a/spec/commands/mapping_create_spec.cr +++ b/spec/commands/mapping_create_spec.cr @@ -3,5 +3,11 @@ require "../../src/commands/mapping_create" describe GX::Commands::MappingCreate do context "Initialization" do + it "initializes with a mock FileSystemManager and RootConfig" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + command = GX::Commands::MappingCreate.new(config) + command.should be_a(GX::Commands::MappingCreate) + end end end diff --git a/spec/commands/mapping_edit_spec.cr b/spec/commands/mapping_edit_spec.cr index a042c80..2bedf71 100644 --- a/spec/commands/mapping_edit_spec.cr +++ b/spec/commands/mapping_edit_spec.cr @@ -3,5 +3,10 @@ require "../../src/commands/mapping_edit" describe GX::Commands::MappingEdit do context "Initialization" do + it "initializes with a mock FileSystemManager" do + config = GX::Config.new + command = GX::Commands::MappingEdit.new(config) + command.should be_a(GX::Commands::MappingEdit) + end end end diff --git a/spec/commands/mapping_list_spec.cr b/spec/commands/mapping_list_spec.cr index 008862a..a0f5890 100644 --- a/spec/commands/mapping_list_spec.cr +++ b/spec/commands/mapping_list_spec.cr @@ -1,7 +1,108 @@ + require "../spec_helper" require "../../src/commands/mapping_list" +require "../../src/models/gocryptfs_config" +require "../../src/models/sshfs_config" +require "../../src/models/httpdirfs_config" describe GX::Commands::MappingList do context "Initialization" do + it "initializes with a mock FileSystemManager and RootConfig" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + command = GX::Commands::MappingList.new(config) + command.should be_a(GX::Commands::MappingList) + end + end + + context "Functioning" do + it "lists mappings when there are no filesystems" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + command = GX::Commands::MappingList.new(config) + + output = capture_output do + command.execute + end + + output.should include("TYPE") + output.should include("NAME") + output.should include("MOUNTED") + end + + it "lists mappings when there are multiple filesystems" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + + gocryptfs_config = GX::Models::GoCryptFSConfig.new( + GX::Parsers::Options::MappingCreateOptions.new( + type: "gocryptfs", + name: "test_gocryptfs", + encrypted_path: "/encrypted/path" + ) + ) + sshfs_config = GX::Models::SshFSConfig.new( + GX::Parsers::Options::MappingCreateOptions.new( + type: "sshfs", + name: "test_sshfs", + remote_user: "user", + remote_host: "host", + remote_path: "/remote/path" + ) + ) + httpdirfs_config = GX::Models::HttpDirFSConfig.new( + GX::Parsers::Options::MappingCreateOptions.new( + type: "httpdirfs", + name: "test_httpdirfs", + url: "http://example.com" + ) + ) + + root_config.add_filesystem(gocryptfs_config) + root_config.add_filesystem(sshfs_config) + root_config.add_filesystem(httpdirfs_config) + + command = GX::Commands::MappingList.new(config) + + output = capture_output do + command.execute + end + + output.should include("gocryptfs") + output.should include("test_gocryptfs") + output.should include("false") + + output.should include("sshfs") + output.should include("test_sshfs") + output.should include("false") + + output.should include("httpdirfs") + output.should include("test_httpdirfs") + output.should include("false") + end + + it "ensures the output format is correct" do + config = GX::Config.new + root_config = GX::Models::RootConfig.new + config.instance_variable_set("@root", root_config) + + gocryptfs_config = GX::Models::GoCryptFSConfig.new( + GX::Parsers::Options::MappingCreateOptions.new( + type: "gocryptfs", + name: "test_gocryptfs", + encrypted_path: "/encrypted/path" + ) + ) + root_config.add_filesystem(gocryptfs_config) + + command = GX::Commands::MappingList.new(config) + + output = capture_output do + command.execute + end + + output.should match(/TYPE\s+NAME\s+MOUNTED/) + output.should match(/gocryptfs\s+test_gocryptfs\s+false/) + end end end -- 2.45.3 From ec98b8920668efd028fc588a744496d0b1f300d5 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Tue, 10 Dec 2024 23:53:30 +0100 Subject: [PATCH 45/53] fix: show progress during build --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f8e3b8a..fb3baac 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ prepare: shards install build: - shards build --error-trace -Dpreview_mt + shards build --progress --error-trace -Dpreview_mt @echo SUCCESS watch: -- 2.45.3 From 4acbaf7d8365eabd763ff63e3b0b8bf508f743ec Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Tue, 10 Dec 2024 23:54:52 +0100 Subject: [PATCH 46/53] fix: cleanup code and comments --- src/commands/config_init.cr | 2 +- src/commands/global_version.cr | 2 +- src/commands/mapping_create.cr | 2 +- src/commands/mapping_delete.cr | 4 ++-- src/commands/mapping_edit.cr | 4 ++-- src/config.cr | 1 - src/file_storage.cr | 1 - src/file_system_manager.cr | 10 +++++----- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/commands/config_init.cr b/src/commands/config_init.cr index df2ecee..2899954 100644 --- a/src/commands/config_init.cr +++ b/src/commands/config_init.cr @@ -18,7 +18,7 @@ module GX::Commands # Override the configuration path if provided puts "Configuration file path: #{config_file_path}" puts "Configuration file path: #{@config.path}" - pp @config + # pp @config @config.path.try do |path| config_file_path = path config_dir = File.dirname(path) diff --git a/src/commands/global_version.cr b/src/commands/global_version.cr index 944f026..5ab5fb3 100644 --- a/src/commands/global_version.cr +++ b/src/commands/global_version.cr @@ -8,7 +8,7 @@ require "../config" module GX::Commands class GlobalVersion < AbstractCommand - def initialize(config : GX::Config) # FIXME + def initialize(config : GX::Config) end def execute diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index 40dbaa7..d2882d1 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -7,7 +7,7 @@ require "./abstract_command" module GX::Commands class MappingCreate < AbstractCommand - def initialize(@config : GX::Config) # FIXME + def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file end diff --git a/src/commands/mapping_delete.cr b/src/commands/mapping_delete.cr index 1849320..60a86e6 100644 --- a/src/commands/mapping_delete.cr +++ b/src/commands/mapping_delete.cr @@ -7,11 +7,11 @@ require "./abstract_command" module GX::Commands class MappingDelete < AbstractCommand - def initialize(config : GX::Config) # FIXME + def initialize(config : GX::Config) end def execute - # FIXME: implement + # TODO: implement end def self.handles_mode diff --git a/src/commands/mapping_edit.cr b/src/commands/mapping_edit.cr index 216cae9..2169173 100644 --- a/src/commands/mapping_edit.cr +++ b/src/commands/mapping_edit.cr @@ -7,11 +7,11 @@ require "./abstract_command" module GX::Commands class MappingEdit < AbstractCommand - def initialize(config : GX::Config) # FIXME + def initialize(config : GX::Config) end def execute - # FIXME: implement + # TODO: implement end def self.handles_mode diff --git a/src/config.cr b/src/config.cr index 853e7cc..cc7f43e 100644 --- a/src/config.cr +++ b/src/config.cr @@ -27,7 +27,6 @@ module GX record AddArgs, name : String, path : String record DelArgs, name : String - # getter filesystems : Array(Models::AbstractFilesystemConfig) getter home_dir : String getter root : Models::RootConfig? diff --git a/src/file_storage.cr b/src/file_storage.cr index 20a9d7b..3726461 100644 --- a/src/file_storage.cr +++ b/src/file_storage.cr @@ -10,4 +10,3 @@ class FileStorage bake_folder "../static" end - diff --git a/src/file_system_manager.cr b/src/file_system_manager.cr index 5281b7c..088382a 100644 --- a/src/file_system_manager.cr +++ b/src/file_system_manager.cr @@ -42,10 +42,10 @@ module GX end def auto_open(filesystem) - # FIXME: detect xdg-open and use it if possible - # FIXME: detect mailcap and use it if no xdg-open found - # FIXME: support user-defined command in configuration - # FIXME: detect graphical environment + # TODO: detect xdg-open and use it if possible + # TODO: detect mailcap and use it if no xdg-open found + # TODO: support user-defined command in configuration + # TODO: detect graphical environment mount_point_safe = filesystem.mount_point raise Models::InvalidMountpointError.new("Invalid filesystem") if mount_point_safe.nil? @@ -111,7 +111,7 @@ module GX } end - # # FIXME: feat: allow to sort by name or by filesystem + # FIXME: feat: allow to sort by name or by filesystem sorted_values = names_display.values.sort_by!(&.[:filesystem].name) result_filesystem_name = Utils::Fzf.run(sorted_values.map(&.[:ansi_name])).strip selected_filesystem = names_display[result_filesystem_name][:filesystem] -- 2.45.3 From 01804f113978232f1a7eefe5c03c79b37b7b5e37 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Tue, 10 Dec 2024 23:58:38 +0100 Subject: [PATCH 47/53] feat: add configuration saving functionality to MappingCreate command --- src/commands/mapping_create.cr | 2 ++ src/config.cr | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index d2882d1..e03db95 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -4,12 +4,14 @@ # Copyright © 2024 Glenn Y. Rolland require "./abstract_command" +require "../models/filesystem_factory" module GX::Commands class MappingCreate < AbstractCommand def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file + @config.save_to_file end def execute diff --git a/src/config.cr b/src/config.cr index cc7f43e..182c186 100644 --- a/src/config.cr +++ b/src/config.cr @@ -120,5 +120,15 @@ module GX end @root = root end + + def save_to_file + return if @path.nil? + if @path + File.write(@path.to_s, @root.to_yaml) + else + Log.error { "Configuration path is nil, cannot save configuration." } + end + Log.info { "Configuration saved to #{@path}" } + end end end -- 2.45.3 From 06e3d1895cc8e5974b16a96edc25eb448e1d873d Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 11 Dec 2024 00:08:11 +0100 Subject: [PATCH 48/53] refactor: Remove direct initialization of file_system_manager in commands --- src/commands/global_tui.cr | 1 - src/commands/mapping_list.cr | 1 - src/commands/mapping_mount.cr | 3 +-- src/commands/mapping_umount.cr | 3 +-- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/commands/global_tui.cr b/src/commands/global_tui.cr index 0b71acd..605d318 100644 --- a/src/commands/global_tui.cr +++ b/src/commands/global_tui.cr @@ -17,7 +17,6 @@ module GX::Commands end def execute - filesystem = @file_system_manager.choose_filesystem raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? @file_system_manager.mount_or_umount(filesystem) @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? diff --git a/src/commands/mapping_list.cr b/src/commands/mapping_list.cr index 3754edd..a3a6286 100644 --- a/src/commands/mapping_list.cr +++ b/src/commands/mapping_list.cr @@ -12,7 +12,6 @@ module GX::Commands def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file - @file_system_manager = FileSystemManager.new(@config) end def execute diff --git a/src/commands/mapping_mount.cr b/src/commands/mapping_mount.cr index 7f2a1af..51cf2b7 100644 --- a/src/commands/mapping_mount.cr +++ b/src/commands/mapping_mount.cr @@ -13,11 +13,10 @@ module GX::Commands def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file - @file_system_manager = FileSystemManager.new(@config) end def execute - filesystem = @file_system_manager.choose_filesystem + filesystem = @config.root.try &.file_system_manager.choose_filesystem raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? filesystem.mount @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? diff --git a/src/commands/mapping_umount.cr b/src/commands/mapping_umount.cr index 77364c2..5e4b929 100644 --- a/src/commands/mapping_umount.cr +++ b/src/commands/mapping_umount.cr @@ -13,11 +13,10 @@ module GX::Commands def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file - @file_system_manager = FileSystemManager.new(@config) end def execute - filesystem = @file_system_manager.choose_filesystem + filesystem = @config.root.try &.file_system_manager.choose_filesystem raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? filesystem.umount end -- 2.45.3 From f3836948706865726782e53c4acb7d16e7e7bd44 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 11 Dec 2024 00:08:26 +0100 Subject: [PATCH 49/53] feat: add support for tracking inherited filesystem config subclasses --- src/models/abstract_filesystem_config.cr | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/models/abstract_filesystem_config.cr b/src/models/abstract_filesystem_config.cr index 928a0d7..66081ee 100644 --- a/src/models/abstract_filesystem_config.cr +++ b/src/models/abstract_filesystem_config.cr @@ -15,6 +15,15 @@ module GX::Models abstract class AbstractFilesystemConfig include YAML::Serializable # include YAML::Serializable::Strict + @@subs = [] of AbstractFilesystemConfig.class + + macro inherited + @@subs << {{@type.name.id}} + end + + def self.subs + @@subs + end use_yaml_discriminator "type", { gocryptfs: GoCryptFSConfig, -- 2.45.3 From 16b81ed0388e00e0a10995df1d88cd3382290fef Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 11 Dec 2024 00:06:44 +0100 Subject: [PATCH 50/53] feat: add initializer for root_config with version and filesystems parameters --- src/models/root_config.cr | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/models/root_config.cr b/src/models/root_config.cr index d88dc61..2227ad6 100644 --- a/src/models/root_config.cr +++ b/src/models/root_config.cr @@ -36,5 +36,12 @@ module GX::Models @[YAML::Field(key: "filesystems")] getter filesystems : Array(AbstractFilesystemConfig) + setter filesystems + + def initialize(version = "1.0.0", global = GlobalConfig.new, filesystems = [] of AbstractFilesystemConfig) + @version = version + @global = global + @filesystems = filesystems + end end end -- 2.45.3 From a3d827bdb09f8c9677e07f7c808e2da0696cae76 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 11 Dec 2024 00:41:04 +0100 Subject: [PATCH 51/53] fix: prepare for evolution of (u)mount management --- src/commands/global_tui.cr | 10 +++++----- src/commands/mapping_create.cr | 1 - src/commands/mapping_mount.cr | 20 +++++++++++++++----- src/commands/mapping_umount.cr | 22 +++++++++++++++++----- src/file_system_manager.cr | 19 ------------------- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/commands/global_tui.cr b/src/commands/global_tui.cr index 605d318..f826873 100644 --- a/src/commands/global_tui.cr +++ b/src/commands/global_tui.cr @@ -8,18 +8,18 @@ require "../file_system_manager" module GX::Commands class GlobalTui < AbstractCommand - @file_system_manager : FileSystemManager + # @file_system_manager : FileSystemManager def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file - @file_system_manager = FileSystemManager.new(@config) + # @file_system_manager = FileSystemManager.new(@config) end def execute - raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? - @file_system_manager.mount_or_umount(filesystem) - @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? + # raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? + # @file_system_manager.mount_or_umount(filesystem) + # @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? end def self.handles_mode diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index e03db95..6dab79e 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -36,7 +36,6 @@ module GX::Commands @config.root.try do |root| root.filesystems ||= [] of GX::Models::AbstractFilesystemConfig root.filesystems << filesystem_config - root.file_system_manager.mount_or_umount(filesystem_config) end puts "Mapping '#{create_options.name}' created and added to configuration successfully." diff --git a/src/commands/mapping_mount.cr b/src/commands/mapping_mount.cr index 51cf2b7..d94f966 100644 --- a/src/commands/mapping_mount.cr +++ b/src/commands/mapping_mount.cr @@ -8,7 +8,7 @@ require "../file_system_manager" module GX::Commands class MappingMount < AbstractCommand - @file_system_manager : FileSystemManager + # @file_system_manager : FileSystemManager def initialize(@config : GX::Config) @config.load_from_env @@ -16,14 +16,24 @@ module GX::Commands end def execute - filesystem = @config.root.try &.file_system_manager.choose_filesystem - raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? - filesystem.mount - @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? + # filesystem = @config.root.try &.file_system_manager.choose_filesystem + # raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? + # filesystem.mount + # @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? + end def self.handles_mode GX::Types::Mode::MappingMount end + + private def _mount_filesystem(filesystem : Models::AbstractFilesystemConfig) + raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? + if filesystem.mounted? + Log.info { "Filesystem already mounted." } + return + end + filesystem.mount + end end end diff --git a/src/commands/mapping_umount.cr b/src/commands/mapping_umount.cr index 5e4b929..137e25a 100644 --- a/src/commands/mapping_umount.cr +++ b/src/commands/mapping_umount.cr @@ -8,21 +8,33 @@ require "../file_system_manager" module GX::Commands class MappingUmount < AbstractCommand - @file_system_manager : FileSystemManager - def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file end def execute - filesystem = @config.root.try &.file_system_manager.choose_filesystem - raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? - filesystem.umount + # root = @config.root + # raise "Missing root config" if root.nil? + + # filesystem = root.file_system_manager.choose_filesystem + # raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? + + # filesystem.umount end def self.handles_mode GX::Types::Mode::MappingUmount end + + # OBSOLETE: + private def umount_filesystem(filesystem : Models::AbstractFilesystemConfig) + raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? + unless filesystem.mounted? + Log.info { "Filesystem is not mounted." } + return + end + filesystem.umount + end end end diff --git a/src/file_system_manager.cr b/src/file_system_manager.cr index 088382a..e8bf6d9 100644 --- a/src/file_system_manager.cr +++ b/src/file_system_manager.cr @@ -13,25 +13,6 @@ module GX def initialize(@config : Config) end - # OBSOLETE: - # def mount_filesystem(filesystem : Models::AbstractFilesystemConfig) - # raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? - # if filesystem.mounted? - # Log.info { "Filesystem already mounted." } - # return - # end - # filesystem.mount - # end - - # OBSOLETE: - # def umount_filesystem(filesystem : Models::AbstractFilesystemConfig) - # raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? - # unless filesystem.mounted? - # Log.info { "Filesystem is not mounted." } - # return - # end - # filesystem.umount - # end def mount_or_umount(selected_filesystem) if !selected_filesystem.mounted? -- 2.45.3 From 7243935bf964cf3d509de3bc8236c8fe4319de77 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 11 Dec 2024 00:52:51 +0100 Subject: [PATCH 52/53] fix: tui should work again --- src/commands/global_tui.cr | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/commands/global_tui.cr b/src/commands/global_tui.cr index f826873..64f1d4d 100644 --- a/src/commands/global_tui.cr +++ b/src/commands/global_tui.cr @@ -13,13 +13,14 @@ module GX::Commands def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file - # @file_system_manager = FileSystemManager.new(@config) + @file_system_manager = FileSystemManager.new(@config) end def execute - # raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? - # @file_system_manager.mount_or_umount(filesystem) - # @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? + filesystem = @file_system_manager.choose_filesystem + raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? + @file_system_manager.mount_or_umount(filesystem) + @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? end def self.handles_mode -- 2.45.3 From bb7510704f61ea7fd92407cec4f53b837339410f Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 11 Dec 2024 01:14:18 +0100 Subject: [PATCH 53/53] refactor: split FileSystemManager choose_filesystem into simpler pieces --- src/commands/mapping_mount.cr | 6 ++-- src/file_system_manager.cr | 62 ++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/commands/mapping_mount.cr b/src/commands/mapping_mount.cr index d94f966..e8ab080 100644 --- a/src/commands/mapping_mount.cr +++ b/src/commands/mapping_mount.cr @@ -8,15 +8,17 @@ require "../file_system_manager" module GX::Commands class MappingMount < AbstractCommand - # @file_system_manager : FileSystemManager def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file + @file_system_manager = FileSystemManager.new(@config) end def execute - # filesystem = @config.root.try &.file_system_manager.choose_filesystem + # get filesystem from config options + # filesystem = @config.mapping_mount_options.filesystem + # raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? # filesystem.mount # @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? diff --git a/src/file_system_manager.cr b/src/file_system_manager.cr index e8bf6d9..a0d8093 100644 --- a/src/file_system_manager.cr +++ b/src/file_system_manager.cr @@ -3,7 +3,7 @@ # SPDX-FileCopyrightText: 2024 Glenn Y. Rolland # Copyright © 2024 Glenn Y. Rolland -# require "./models/abstract_filesystem_config" +require "./models/abstract_filesystem_config" require "./utils/fzf" module GX @@ -23,7 +23,7 @@ module GX end def auto_open(filesystem) - # TODO: detect xdg-open and use it if possible + # TODO: detect xdg-open presence and use it if possible # TODO: detect mailcap and use it if no xdg-open found # TODO: support user-defined command in configuration # TODO: detect graphical environment @@ -31,7 +31,7 @@ module GX mount_point_safe = filesystem.mount_point raise Models::InvalidMountpointError.new("Invalid filesystem") if mount_point_safe.nil? - if graphical_environment? + if _graphical_environment? process = Process.new( "xdg-open", # # FIXME: make configurable [mount_point_safe], @@ -74,23 +74,13 @@ module GX config_root.filesystems end + # Get filesystem by name + def detect_filesystem(filesystem_name : String) : GX::Models::AbstractFilesystemConfig? + end + + # Choose filesystem with fzf def choose_filesystem : GX::Models::AbstractFilesystemConfig? - names_display = {} of String => NamedTuple( - filesystem: Models::AbstractFilesystemConfig, - ansi_name: String) - - config_root = @config.root - return if config_root.nil? - - config_root.filesystems.each do |filesystem| - result_name = _fzf_plain_name(filesystem) - ansi_name = _fzf_ansi_name(filesystem) - - names_display[result_name] = { - filesystem: filesystem, - ansi_name: ansi_name, - } - end + names_display = _filesystem_table # FIXME: feat: allow to sort by name or by filesystem sorted_values = names_display.values.sort_by!(&.[:filesystem].name) @@ -117,11 +107,43 @@ module GX "#{fs_str} #{filesystem.name} #{suffix}".strip end - private def graphical_environment? + private def _graphical_environment? if ENV["DISPLAY"]? || ENV["WAYLAND_DISPLAY"]? return true end false end + + + alias FilesystemTableItem = + NamedTuple( + filesystem: Models::AbstractFilesystemConfig, + ansi_name: String + ) + + alias FilesystemTable = + Hash( + String, + FilesystemTableItem + ) + + private def _filesystem_table : FilesystemTable + names_display = {} of String => FilesystemTableItem + + config_root = @config.root + return {} of String => FilesystemTableItem if config_root.nil? + + config_root.filesystems.each do |filesystem| + result_name = _fzf_plain_name(filesystem) + ansi_name = _fzf_ansi_name(filesystem) + + names_display[result_name] = { + filesystem: filesystem, + ansi_name: ansi_name, + } + end + + names_display + end end end -- 2.45.3