From 2df4e01d45a6ef9656da9adc31b0a95e32655227 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Thu, 4 Jul 2024 23:34:54 -0300 Subject: [PATCH] Use rucksack to embed known runtimes in the binary --- .gitignore | 2 ++ shard.lock | 8 ++++---- shard.yml | 5 +++++ src/commands/new.cr | 18 ++++++++++++++++-- src/main.cr | 20 ++++++++++---------- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index d4dbc30..7c7ed9b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ tmp/ export/ secrets/ +.rucksack +.rucksack.toc diff --git a/shard.lock b/shard.lock index 8e51532..dbfe162 100644 --- a/shard.lock +++ b/shard.lock @@ -40,11 +40,11 @@ shards: git: https://github.com/kemalcr/kemal.git version: 1.5.0 - kemal-basic-auth: - git: https://github.com/kemalcr/kemal-basic-auth.git - version: 1.0.0 - radix: git: https://github.com/luislavena/radix.git version: 0.4.1 + rucksack: + git: https://github.com/busyloop/rucksack.git + version: 2.0.0 + diff --git a/shard.yml b/shard.yml index 59656b7..1c792aa 100644 --- a/shard.yml +++ b/shard.yml @@ -28,3 +28,8 @@ dependencies: branch: add_exposed_ports kemal: github: kemalcr/kemal + rucksack: + github: busyloop/rucksack + +scripts: + postinstall: cat .rucksack >> bin/faaso \ No newline at end of file diff --git a/src/commands/new.cr b/src/commands/new.cr index 21dfa3a..4e60a52 100644 --- a/src/commands/new.cr +++ b/src/commands/new.cr @@ -1,12 +1,26 @@ +require "rucksack" + module Faaso module Commands # Creates a new empty funko out of a given runtime struct New + @@known : Array(String) = {{`find ./runtimes -type d -mindepth 1`.split('\n').reject(&.empty?)}} + def run(options, folder) - if options["RUNTIME"].as(String) == "list" - Log.info {"Known runtimes:"} + if options["-r"].as(String) == "list" + Log.info { "Crystal has some included runtimes:\n" } + @@known.each do |runtime| + Log.info { " * #{Path[runtime].basename}" } + end + Log.info { "\nOr if you have your own, use a folder name" } + return 0 end end end end end + +# Embed runtimes in the binary using rucksack +{% for name in `find ./runtimes -type f`.split('\n') %} + rucksack({{name}}) +{% end %} diff --git a/src/main.cr b/src/main.cr index a6433f0..4b9372a 100644 --- a/src/main.cr +++ b/src/main.cr @@ -46,12 +46,12 @@ doc = <<-DOC FaaSO CLI tool. Usage: - faaso build FOLDER ... [-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 build FOLDER ... [-v ] [-l] + faaso export SOURCE DESTINATION [-v ] + faaso new -r runtime FOLDER [-v ] + faaso scale FUNKO [SCALE] [-v ] [-l] + faaso secret (-d|-a) FUNKO SECRET [-v ] [-l] + faaso status FUNKO [-v ] [-l] faaso version Options: @@ -59,8 +59,8 @@ Options: -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] + -r runtime Runtime for the new funko (use -r list for examples) + -v level Control the logging verbosity, 0 to 5 [default: 3] DOC ans = Docopt.docopt(doc, ARGV) @@ -72,8 +72,8 @@ 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("new", false) + Faaso::Commands::New.new.run(ans, ans["FOLDER"].as(Array(String))[0]) when .fetch("scale", false) Faaso::Commands::Scale.new.run(ans, ans["FUNKO"].as(String), ans["SCALE"]) when .fetch("secret", false)