Compare commits

..

No commits in common. "2990e18b27c716726c1e302e39594023f9cf4a53" and "47c9dbcd899ad963b657a49dd5aff910e68e3c86" have entirely different histories.

3 changed files with 4 additions and 53 deletions

View file

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

View file

@ -7,8 +7,6 @@ require "./filesystems"
module GX module GX
class Config class Config
Log = ::Log.for("config")
enum Mode enum Mode
ConfigAdd ConfigAdd
ConfigDelete ConfigDelete
@ -28,6 +26,8 @@ module GX
property path : String property path : String
property args : AddArgs.class | DelArgs.class | NoArgs.class property args : AddArgs.class | DelArgs.class | NoArgs.class
DEFAULT_CONFIG_PATH = "mfm.yml"
def initialize() def initialize()
if !ENV["HOME"]? if !ENV["HOME"]?
raise "Home directory not found" raise "Home directory not found"
@ -37,39 +37,15 @@ module GX
@verbose = false @verbose = false
@mode = Mode::Mount @mode = Mode::Mount
@filesystems = [] of Filesystem @filesystems = [] of Filesystem
@path = detect_config_file() @path = File.join(@home_dir, ".config", DEFAULT_CONFIG_PATH)
@args = NoArgs @args = NoArgs
end 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 def load_from_file
@filesystems = [] of Filesystem @filesystems = [] of Filesystem
if !File.exists? @path if !File.exists? @path
Log.error { "File #{@path} does not exist!".colorize(:red) } STDERR.puts "Error: file #{@path} does not exist!".colorize(:red)
exit(1) exit(1)
end end
load_filesystems(@path) load_filesystems(@path)

View file

@ -6,33 +6,11 @@
require "yaml" require "yaml"
require "colorize" require "colorize"
require "json" require "json"
require "log"
require "./filesystems/gocryptfs" require "./filesystems/gocryptfs"
require "./config" require "./config"
require "./cli" 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 = GX::Cli.new
app.parse_command_line(ARGV) app.parse_command_line(ARGV)
app.run app.run