Fix input/output cli flags for new core.os package
This commit is contained in:
+9
-6
@@ -5,11 +5,11 @@ import "core:fmt"
|
|||||||
import "core:os"
|
import "core:os"
|
||||||
|
|
||||||
Options :: struct {
|
Options :: struct {
|
||||||
verbose: bool `args:"name=verbose" usage:"Enable verbose output"`,
|
verbose: bool `args:"name=verbose" usage:"Enable verbose output"`,
|
||||||
compression: u8 `args:"name=compression" usage:"Compression level, 0-12"`,
|
compression: u8 `args:"name=compression" usage:"Compression level, 0-12"`,
|
||||||
size: i64 `args:"name=size" usage:"Chunk size in bytes"`,
|
size: i64 `args:"name=size" usage:"Chunk size in bytes"`,
|
||||||
input: os.Handle `args:"name=input,file=r,required" usage:"Path to input directory"`,
|
input: ^os.File `args:"name=input,file=r,required" usage:"Path to input directory"`,
|
||||||
output: os.Handle `args:"name=output,file=wc" usage:"Path to ouput directory"`,
|
output: ^os.File `args:"name=output,file=wc" usage:"Path to ouput directory"`,
|
||||||
// overflow: [dynamic]string,
|
// overflow: [dynamic]string,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,10 @@ parse :: proc() -> Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if opts.compression > 12 {
|
if opts.compression > 12 {
|
||||||
fmt.eprintln("error: compression should be between 0-12")
|
fmt.eprintln(
|
||||||
|
"error: compression higher than allowed maximum:",
|
||||||
|
opts.compression,
|
||||||
|
)
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package file
|
||||||
|
|
||||||
|
import "core:fmt"
|
||||||
|
import "core:os"
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// - list files in directory
|
||||||
|
// - get relative path
|
||||||
|
// - read file contents
|
||||||
|
// - write file contents
|
||||||
|
|
||||||
|
Asset :: struct {
|
||||||
|
path: string,
|
||||||
|
size: i64,
|
||||||
|
data: []u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
read :: proc(f: ^os.File) -> Asset {
|
||||||
|
path := os.name(f)
|
||||||
|
|
||||||
|
size, err := os.file_size(f)
|
||||||
|
if err != nil {
|
||||||
|
fmt.eprintln("error: failed to get file size:", err)
|
||||||
|
os.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
data := make([]u8, size)
|
||||||
|
|
||||||
|
n, read_err := os.read_full(f, data)
|
||||||
|
if read_err != nil {
|
||||||
|
fmt.eprintln("read failed:", read_err, "got", n, "of", size, "bytes")
|
||||||
|
os.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Asset{path = path, size = size, data = data}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
|
|
||||||
import "src:cli"
|
import "src:cli"
|
||||||
|
import "src:file"
|
||||||
|
|
||||||
VERSION :: #config(VERSION, "dev")
|
VERSION :: #config(VERSION, "dev")
|
||||||
|
|
||||||
@@ -12,4 +13,9 @@ main :: proc() {
|
|||||||
fmt.println("verbose:", opts.verbose)
|
fmt.println("verbose:", opts.verbose)
|
||||||
fmt.println("compression:", opts.compression)
|
fmt.println("compression:", opts.compression)
|
||||||
fmt.println("size:", opts.size)
|
fmt.println("size:", opts.size)
|
||||||
|
|
||||||
|
asset := file.read(opts.input)
|
||||||
|
fmt.println("path:", asset.path)
|
||||||
|
fmt.println("size:", asset.size)
|
||||||
|
fmt.println("data:", asset.data)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user