From 50ac47643775ce4067dc25b73330494d623a547b Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Thu, 4 Jul 2024 22:34:13 -0300 Subject: [PATCH] Log info and nicer to stdout, worse to stderr. Colorize only on tty. --- src/commands/new.cr | 12 ++++++++++++ src/faaso.cr | 1 + src/main.cr | 47 +++++++++++++++++++++++++++++---------------- 3 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 src/commands/new.cr diff --git a/src/commands/new.cr b/src/commands/new.cr new file mode 100644 index 0000000..21dfa3a --- /dev/null +++ b/src/commands/new.cr @@ -0,0 +1,12 @@ +module Faaso + module Commands + # Creates a new empty funko out of a given runtime + struct New + def run(options, folder) + if options["RUNTIME"].as(String) == "list" + Log.info {"Known runtimes:"} + end + end + end + end +end diff --git a/src/faaso.cr b/src/faaso.cr index 2a29444..2ae7175 100644 --- a/src/faaso.cr +++ b/src/faaso.cr @@ -1,5 +1,6 @@ require "./commands/build.cr" require "./commands/export.cr" +require "./commands/new.cr" require "./commands/scale.cr" require "./commands/secret.cr" require "./commands/status.cr" diff --git a/src/main.cr b/src/main.cr index 094885b..a6433f0 100644 --- a/src/main.cr +++ b/src/main.cr @@ -18,17 +18,26 @@ struct LogFormat < Log::StaticFormatter end def self.setup(verbosity) - _verbosity = [ - Log::Severity::Fatal, - Log::Severity::Error, - Log::Severity::Warn, - Log::Severity::Info, - Log::Severity::Debug, - Log::Severity::Trace, - ][[verbosity, 5].min] + Colorize.on_tty_only! + if verbosity < 3 + _verbosity = [ + Log::Severity::Fatal, + Log::Severity::Error, + Log::Severity::Warn, + ][[verbosity, 2].min] + Log.setup( + _verbosity, + Log::IOBackend.new(io: STDERR, formatter: LogFormat) + ) + end + + _verbosity = [Log::Severity::Info, + Log::Severity::Debug, + Log::Severity::Trace, + ][[verbosity - 3, 3].min] Log.setup( _verbosity, - Log::IOBackend.new(io: STDERR, formatter: LogFormat) + Log::IOBackend.new(io: STDOUT, formatter: LogFormat) ) end end @@ -38,17 +47,19 @@ FaaSO CLI tool. Usage: faaso build FOLDER ... [-v=] [-l] - faaso scale FUNKO [SCALE] [-v=] [-l] - faaso status FUNKO [-v=] [-l] faaso export SOURCE DESTINATION [-v=] + faaso new -r FOLDER [-v=] + faaso scale FUNKO [SCALE] [-v=] [-l] faaso secret [-d|-a] FUNKO SECRET [-v=] [-l] + faaso status FUNKO [-v=] [-l] + faaso version Options: - -l --local Run commands locally instead of against a FaaSO server. - -h --help Show this screen. - -d --delete Delete -a --add Add - --version Show version. + -d --delete Delete + -h --help Show this screen + -l --local Run commands locally instead of against a FaaSO server + -r --runtime Runtime for the new funko (use -r list for examples) -v=level Control the logging verbosity, 0 to 5 [default: 3] DOC @@ -61,10 +72,12 @@ when .fetch("build", false) Faaso::Commands::Build.new.run(ans, ans["FOLDER"].as(Array(String))) when .fetch("export", false) Faaso::Commands::Export.new.run(ans, ans["SOURCE"].as(String), ans["DESTINATION"].as(String)) +# when .fetch("new", false) +# Faaso::Commands::New.new.run(ans, ans["FOLDER"].as(String)) when .fetch("scale", false) Faaso::Commands::Scale.new.run(ans, ans["FUNKO"].as(String), ans["SCALE"]) -when .fetch("status", false) - Faaso::Commands::Status.new.run(ans, ans["FUNKO"].as(String)) when .fetch("secret", false) Faaso::Commands::Secret.new.run(ans, ans["FUNKO"].as(String), ans["SECRET"].as(String)) +when .fetch("status", false) + Faaso::Commands::Status.new.run(ans, ans["FUNKO"].as(String)) end