diff options
| author | Alejandro Sior <aho@sior.be> | 2022-06-18 14:43:46 +0200 |
|---|---|---|
| committer | Alejandro Sior <aho@sior.be> | 2022-06-18 14:43:46 +0200 |
| commit | fd2f5a94d6ad595e8bed354eca168a82b882e8b4 (patch) | |
| tree | f30495b2ca343e1baf189e8a9f20f6234848fdea /create/create.ha | |
| parent | 6117a803ad717fd50003c0bd8fbe393db2dcac6b (diff) | |
gptman: change the way of how args are passed to subcommands
Diffstat (limited to 'create/create.ha')
| -rw-r--r-- | create/create.ha | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/create/create.ha b/create/create.ha index 2c08eec..b7dc0f7 100644 --- a/create/create.ha +++ b/create/create.ha @@ -1,12 +1,38 @@ use fmt; +use fs; +use getopt; use io; +use os; +use strconv; use gpt; +use volume; -export fn create(vol: io::file, args: []str) void = { +export fn create(vol: str, args: []str) void = { // XXX this is a stub - const vol = gpt::create(vol, 1000); + const cmd = getopt::parse(args, + "create a volume", + ('f', "file", "specify another partition file to fit"), + ('l', "length", "specify another length margin") + ); + defer getopt::finish(&cmd); + + let length = 0z; + + for (let i = 0z; i < len(cmd.opts); i += 1) { + const opt = cmd.opts[i]; + switch (opt.0) { + case 'l' => + length += (strconv::stoi(opt.1)! / 512 + 1): size; + case 'f' => + const stat = os::stat(opt.1)!; + length += stat.sz / 512 + 1; + }; + }; + + const vol = volume::mkvol(vol); + const vol = gpt::create(vol, length); defer { gpt::chksums(vol); gpt::commit(vol)!; |
