Compare commits

..

4 commits

Author SHA1 Message Date
6d36a7f78a ci: switch to alpine for static linking
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
2023-11-18 23:23:39 +01:00
87bcce48dd ci: bump crystal version
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
2023-11-18 20:19:51 +01:00
4d5d9e3d09 ci: add missing dependencies
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
2023-11-18 20:03:57 +01:00
1969ab8a0f fix: add templating support in configuration
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
Refs: #15
2023-11-18 19:56:03 +01:00
3 changed files with 7 additions and 61 deletions

View file

@ -11,7 +11,6 @@ module GX
VERSION="v0.1.9"
class Cli
Log = ::Log.for("cli")
@config : Config
@ -30,12 +29,10 @@ module GX
parser.banner = "Usage: #{PROGRAM_NAME} [options]\n\nGlobal options"
parser.on("-c", "--config FILE", "Set configuration file") do |path|
Log.info { "Configuration set to #{path}" }
@config.path = path
end
parser.on("-v", "--verbose", "Set more verbosity") do |flag|
Log.info { "Verbosity enabled" }
@config.verbose = true
end

View file

@ -9,8 +9,6 @@ require "./filesystems"
module GX
class Config
Log = ::Log.for("config")
enum Mode
ConfigAdd
ConfigDelete
@ -27,9 +25,11 @@ module GX
getter home_dir : String
property verbose : Bool
property mode : Mode
property path : String?
property path : String
property args : AddArgs.class | DelArgs.class | NoArgs.class
DEFAULT_CONFIG_PATH = "mfm.yml"
def initialize()
if !ENV["HOME"]?
raise "Home directory not found"
@ -39,47 +39,18 @@ module GX
@verbose = false
@mode = Mode::Mount
@filesystems = [] of Filesystem
@path = nil
@path = File.join(@home_dir, ".config", DEFAULT_CONFIG_PATH)
@args = NoArgs
end
def detect_config_file()
possible_files = [
File.join(@home_dir, ".config", "mfm", "config.yaml"),
File.join(@home_dir, ".config", "mfm", "config.yml"),
File.join(@home_dir, ".config", "mfm.yaml"),
File.join(@home_dir, ".config", "mfm.yml"),
File.join("/etc", "mfm", "config.yaml"),
File.join("/etc", "mfm", "config.yml"),
]
possible_files.each do |file_path|
if File.exists?(file_path)
Log.info { "Configuration file found: #{file_path}" }
return file_path if File.exists?(file_path)
else
Log.debug { "Configuration file not found: #{file_path}" }
end
end
Log.error { "No configuration file found in any of the standard locations" }
raise "Configuration file not found"
end
def load_from_file
path = @path
if path.nil?
path = detect_config_file()
end
@path = path
@filesystems = [] of Filesystem
if !File.exists? path
Log.error { "File #{path} does not exist!".colorize(:red) }
if !File.exists? @path
STDERR.puts "Error: file #{@path} does not exist!".colorize(:red)
exit(1)
end
load_filesystems(path)
load_filesystems(@path)
end
private def load_filesystems(config_path : String)

View file

@ -6,33 +6,11 @@
require "yaml"
require "colorize"
require "json"
require "log"
require "./filesystems/gocryptfs"
require "./config"
require "./cli"
struct BaseFormat < Log::StaticFormatter
def run
string @entry.severity.label.downcase
string "("
source
string "): "
message
end
end
Log.setup do |config|
backend = Log::IOBackend.new(formatter: BaseFormat)
config.bind "*", Log::Severity::Info, backend
if ENV["LOG_LEVEL"]?
level = Log::Severity.parse(ENV["LOG_LEVEL"]) || Log::Severity::Info
config.bind "*", level, backend
end
end
app = GX::Cli.new
app.parse_command_line(ARGV)
app.run