some preliminary work done on an argument parser & help menu/docs

This commit is contained in:
Stefan Stefanov 2024-04-26 23:31:21 +03:00
parent 44e88f7fd0
commit 0ef07b299c
5 changed files with 126 additions and 24 deletions

13
.vscode/settings.json vendored
View file

@ -1,7 +1,10 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#322C2D",
"titleBar.activeBackground": "#463E3F",
"titleBar.activeForeground": "#FAFAFA"
}
"workbench.colorCustomizations": {
"activityBar.background": "#322C2D",
"titleBar.activeBackground": "#463E3F",
"titleBar.activeForeground": "#FAFAFA"
},
"[odin]": {
"editor.formatOnSave": true
}
}

2
.vscode/tasks.json vendored
View file

@ -77,7 +77,7 @@
"label": "Build&Run Atlas Generator Test",
"type": "shell",
"windows": {
"command": "${workspaceFolder}/scripts/build_generator_debug.bat && build_generator\\aseprite_odin_generator.exe",
"command": "${workspaceFolder}/scripts/build_generator_debug.bat && build_generator\\aseprite_odin_generator.exe -input-files:value_of_custom_arg -h",
},
"options": {
"cwd": "${workspaceFolder}"

View file

@ -14,13 +14,25 @@ import rl "vendor:raylib"
import stbrp "vendor:stb/rect_pack"
import gen ".."
import utils "../utils"
ATLAS_SIZE :: 512
IMPORT_PATH :: "./src/aseprite_odin_generator/big.aseprite"
EXPORT_PATH :: "./src/aseprite_odin_generator/atlas.png"
main :: proc() {
fmt.println("Hello!")
args := utils.parse_arguments(os.args[1:])
fmt.println(args)
if ok := utils.CLIFlagType.Help in args; ok {
fmt.println("Help called!")
utils.print_help()
return
}
// if help, ok: args[utils.CLIFlagType.Help]; ok {
// fmt.println("Help called!")
// }
ase_file, ase_ok := os.read_entire_file(IMPORT_PATH)
if !ase_ok {
fmt.panicf("Couldn't load file!")
@ -45,20 +57,4 @@ main :: proc() {
)
rl.ExportImage(atlas, EXPORT_PATH)
// something : string = "hello"
// fmt.printf("{1} {2} else", something, 10)
// TestStruct :: struct {
// something: struct {
// name: string,
// age: int,
// },
// }
// ts: TestStruct
// ts.something.name = "name"
// jb, err := json.marshal(ts)
// sjb := transmute(string)jb
// fmt.println(sjb)
}

96
src/utils/cli.odin Normal file
View file

@ -0,0 +1,96 @@
package utils
import "core:fmt"
import s "core:strings"
CLIFlagType :: enum {
Unknown,
InputFiles,
InputFolder,
OutputFolder,
ConfigPath,
EnableMetadataOutput,
MetadataJSONOutputPath,
SourceCodeOutputPathOutputPath,
Help,
}
CLI_FLAG_STRINGS := [CLIFlagType][]string {
.Unknown = {""},
.Help = {"h", "help"},
.InputFiles = {"f", "input-files"},
.InputFolder = {"d", "input-directory"},
.OutputFolder = {"o", "out"},
.EnableMetadataOutput = {"m", "export-metadata"},
.ConfigPath = {"c", "config"},
.MetadataJSONOutputPath = {"j", "json-path"},
.SourceCodeOutputPathOutputPath = {"s", "source-path"},
}
CLI_FLAG_DESCRIPTIONS := [CLIFlagType]string {
.Unknown = "Invalid flag",
.Help = "Prints the help message... hello!",
.InputFiles = "(real) path the source files for the packer (realpaths only), for multiple files you can provide one string of concateneted paths, separated by a ';'",
.InputFolder = "(real) path to a folder full of source files. This is an alternative to the -i[,input-files] flag",
.OutputFolder = "(real) path to the output folder for all the resulting files to be saved to.",
.EnableMetadataOutput = "On by default. Whether or not to export metadata (JSON or source files with the offsets for the packer sprites in the atlas)",
.ConfigPath = "(real) path to a config file (json) that contains string definitions for exporting custom source files. More on this in the docs.",
.MetadataJSONOutputPath = "(real) path for the resulting JSON that will be generated for the atlas. It overrides the name & location in regards to the -o[,output-folder] flag",
.SourceCodeOutputPathOutputPath = "(real) path for the resulting source code file that will be generated for the atlas. It overrides the name & location in regards to the -o[,output-folder] flag",
}
CLIFlag :: struct {
flag: string,
value: string,
cli_type: CLIFlagType,
}
categorize_arg :: proc(flag: string) -> (flag_type: CLIFlagType) {
flag_type = .Unknown
for flag_strings, enum_flag_type in CLI_FLAG_STRINGS {
for flag_string in flag_strings {
if flag == flag_string {
flag_type = enum_flag_type
return
}
}
}
return
}
print_help :: proc() {
for flag in CLIFlagType {
if flag == .Unknown do continue
fmt.printfln(
"Flag: -%v,%v \t -- %v",
CLI_FLAG_STRINGS[flag][0],
CLI_FLAG_STRINGS[flag][1],
CLI_FLAG_DESCRIPTIONS[flag],
)
}
}
parse_arguments :: proc(args: []string) -> (cliargs: map[CLIFlagType]CLIFlag) {
cliargs = make(map[CLIFlagType]CLIFlag)
for arg in args {
arg_name_and_value, err := s.split(arg, ":")
name := arg_name_and_value[0]
if name[0] == '-' {
name = name[1:]
value: string
flag_type := categorize_arg(name)
if len(arg_name_and_value) > 1 {
value = arg_name_and_value[1]
}
map_insert(&cliargs, flag_type, CLIFlag{name, value, flag_type})
}
}
return
}

View file

@ -5,6 +5,13 @@ package utils
import "core:intrinsics"
import "core:reflect"
import "core:strings"
import rl "vendor:raylib"
Texture :: rl.Texture
Color :: rl.Color
Rect :: rl.Rectangle
RectEmpty :: Rect{}
increase_or_wrap_enum :: proc(e: $T) -> T {
ei := int(e) + 1
@ -45,4 +52,4 @@ Vec2 :: [2]f32
vec2_from_vec2i :: proc(p: Vec2i) -> Vec2 {
return {f32(p.x), f32(p.y)}
}
}