new implementation

This commit is contained in:
ge
2026-05-05 23:02:06 +03:00
parent 171ec8fe4b
commit 95ceb5aeac
9 changed files with 179 additions and 217 deletions
+10 -8
View File
@@ -1,11 +1,13 @@
mkembedfs - generate V code for embed directories with files into executable.
mkembedfs - generate V code to embed directories into executables.
usage: mkembedfs [flags] [<path>]
flags:
-help print this help message and exit
-chdir <string> change working directory before codegen
-prefix <string> path prefix for file keys, none by default
-help print this help message and exit.
-chdir <string> change working directory before codegen.
-ignore <string> path globs to ignore (allowed multiple times)
-module-name <string> generated module name, 'main' by default
-const-name <string> generated constant name with data, 'embedfs' by default
-no-pub do not make symbols in generated module public
-force-mimetype set 'application/octet-stream' mime type for unknown files
-prefix <string> path prefix for file keys, none by default.
-path-prefix <string> path prefix for files in $embed_file() calls.
-compression apply zlib compression to $embed_file().
-module-name <string> generated module name, 'main' by default.
-const-name <string> generated const name, 'embed_files' by default.
-no-pub do not make symbols in generated module public.
-notice <string> notice comment text, set empty to disable.
+28 -21
View File
@@ -5,9 +5,9 @@ import flag
import embedfs
fn main() {
mut path := os.getwd()
mut flags, no_matches := flag.to_struct[FlagConfig](os.args, skip: 1, style: .v) or {
eprintln('cmdline parsing error, see -help for info')
mut path := '.'
mut flags, no_matches := flag.to_struct[FlagConfig](os.args, skip: 1, style: .go_flag) or {
println('cmdline parsing error, see -help for info')
exit(2)
}
if no_matches.len > 1 {
@@ -26,25 +26,32 @@ fn main() {
exit(1)
}
}
generator := embedfs.CodeGenerator{
path: path
prefix: flags.prefix
ignore_patterns: flags.ignore
module_name: flags.module_name
const_name: flags.const_name
make_pub: if flags.no_pub { false } else { true }
force_mimetype: flags.force_mimetype
}
println(generator.generate())
dump(flags)
dump(path)
code := embedfs.generate(path,
key_path_prefix: flags.prefix
file_path_prefix: flags.path_prefix
ignore: flags.ignore
module_name: flags.module_name
const_name: flags.const_name
const_public: !flags.no_pub
notice: flags.notice
compression: flags.compression
)!
print(code)
flush_stdout()
}
struct FlagConfig {
help bool
chdir string
prefix string
ignore []string
module_name string = 'main'
const_name string = 'embedfs'
no_pub bool
force_mimetype bool
mut:
help bool
chdir string
ignore []string
prefix string
path_prefix string
module_name string = 'main'
const_name string = 'embed_files'
no_pub bool
notice string = 'This file is generated by embedfs module, DO NOT EDIT!'
compression bool
}