diff --git a/Taskfile.yml b/Taskfile.yml index 54dbe2a..8b4dee4 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -30,7 +30,7 @@ tasks: test: desc: Run test cmds: - - v test . + - v test commands/ vet: desc: Report suspicious code constructs @@ -41,6 +41,8 @@ tasks: desc: Format .v files cmds: - v fmt -w *.v + - v fmt -w commands/*.v + - v fmt -w template/*.v clean: desc: Clean test files diff --git a/vss.v b/commands/build.v similarity index 75% rename from vss.v rename to commands/build.v index c2430f0..0b2c305 100644 --- a/vss.v +++ b/commands/build.v @@ -1,4 +1,4 @@ -module main +module commands import os import cli @@ -20,37 +20,24 @@ const default_index = 'index.md' const default_dist = 'dist' -fn main() { - mut app := cli.Command{ - name: 'vss' - version: '0.0.7' - description: 'static site generator' +fn new_build_cmd() cli.Command { + return cli.Command{ + name: 'build' + description: 'build your site' + usage: 'vss build' execute: fn (cmd cli.Command) ? { - println(cmd.help_message()) + build()? } - commands: [ - cli.Command{ - name: 'build' - description: 'build your site' - usage: 'vss build' - execute: fn (cmd cli.Command) ? { - build()? - } - }, - ] } - - app.setup() - app.parse(os.args) } fn get_config_map() ?map[string]string { mut config_map := map[string]string{} // https://modules.vlang.io/toml.html - config := toml.parse_file(default_config)? + config := toml.parse_file(commands.default_config)? - for param in config_params { + for param in commands.config_params { v := config.value_opt(param) or { continue } config_map[param] = v.string() } @@ -81,7 +68,7 @@ fn pre_proc_md_to_html(contents string) ?string { } fn build() ? { - dist := default_dist + dist := commands.default_dist if os.exists(dist) { os.rmdir_all(dist)? os.mkdir_all(dist)? @@ -90,11 +77,11 @@ fn build() ? { } // copy static files - if os.exists(defautl_static) { - os.cp_all(defautl_static, dist, false)? + if os.exists(commands.defautl_static) { + os.cp_all(commands.defautl_static, dist, false)? } - template_content := os.read_file(default_template)? + template_content := os.read_file(commands.default_template)? mut config_map := get_config_map()? md_paths := os.walk_ext('.', '.md') diff --git a/vss_test.v b/commands/build_test.v similarity index 100% rename from vss_test.v rename to commands/build_test.v diff --git a/commands/vss.v b/commands/vss.v new file mode 100644 index 0000000..19fa8c2 --- /dev/null +++ b/commands/vss.v @@ -0,0 +1,20 @@ +module commands + +import os +import cli + +pub fn execute() { + mut app := cli.Command{ + name: 'vss' + version: '0.0.7' + description: 'static site generator' + execute: fn (cmd cli.Command) ? { + println(cmd.help_message()) + } + } + + app.add_command(new_build_cmd()) + + app.setup() + app.parse(os.args) +} diff --git a/main.v b/main.v new file mode 100644 index 0000000..7ebf9f2 --- /dev/null +++ b/main.v @@ -0,0 +1,7 @@ +module main + +import commands + +fn main() { + commands.execute() +}