From adb8ce2667425b81ade74f87521b2f36d42f60fe Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Sun, 30 Jun 2024 10:49:50 -0300 Subject: [PATCH] Added funko export functionality --- .gitignore | 1 + src/faaso.cr | 25 +++++++++++++++++++++++++ src/funko.cr | 4 ++-- src/main.cr | 13 +++++++++++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f7ad223..8de7c79 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /.shards/ *.dwarf tmp/ +export/ diff --git a/src/faaso.cr b/src/faaso.cr index 7c82f19..63d1a89 100644 --- a/src/faaso.cr +++ b/src/faaso.cr @@ -105,6 +105,31 @@ module Faaso end end + class Export + @arguments : Array(String) = [] of String + @options : Commander::Options + + def initialize(options, arguments) + @options = options + @arguments = arguments + end + + def run + funkos = Funko.from_paths(@arguments) + funkos.each do |funko| + # Create temporary build location + dst_path = Path.new("export", funko.name) + if File.exists? dst_path + puts "Error: #{dst_path} already exists, not exporting #{funko.path}" + next + end + puts "Exporting #{funko.path} to #{dst_path}" + Dir.mkdir_p(dst_path) + funko.prepare_build dst_path + end + end + end + class Down @arguments : Array(String) = [] of String @options : Commander::Options diff --git a/src/funko.cr b/src/funko.cr index 6eb169f..0564f05 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -12,10 +12,10 @@ class Funko # if Nil, it has no template whatsoever property runtime : (String | Nil)? = nil - # Extra packages shipped with the Docker image + # Extra operating system packages shipped with the runtime's Docker image property ship_packages : Array(String) = [] of String - # Extra packages used only in the *build* image + # Extra operating system packages used only when *building* the funko property devel_packages : Array(String) = [] of String # Where this is located in the filesystem diff --git a/src/main.cr b/src/main.cr index 42886bd..9bb3416 100644 --- a/src/main.cr +++ b/src/main.cr @@ -34,12 +34,21 @@ cli = Commander::Command.new do |cmd| cmd.commands.add do |command| command.use = "down" - command.short = "Stop a function" - command.long = "Stop a function in a container" + command.short = "Stop a funko" + command.long = "Stop a funko in a container" command.run do |options, arguments| Faaso::Commands::Down.new(options, arguments).run end end + + cmd.commands.add do |command| + command.use = "export" + command.short = "Export a funko to a directory" + command.long = "Exports a funko as a self-contained directory." + command.run do |options, arguments| + Faaso::Commands::Export.new(options, arguments).run + end + end end Commander.run(cli, ARGV)