diff --git a/.gitignore b/.gitignore index 6bfb124..d4b76a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /bin /dist -# atlas -*.workspace -src/nim.cfg +nimbledeps +nimble.develop +nimble.paths diff --git a/config.nims b/config.nims new file mode 100644 index 0000000..c6ffe96 --- /dev/null +++ b/config.nims @@ -0,0 +1,24 @@ +import std/[strformat, strutils] + +task build, "build": + exec "nim c --outdir:bin src/forge.nim" + +task release, "build release assets": + version = (gorgeEx "git describe --tags --always --match 'v*'").output + exec fmt"./bin/forge release -v {version} -V" + +task bundle, "package build assets": + withDir "dist": + for dir in listDirs("."): + let cmd = + if "windows" in dir: fmt"7z a {dir}.zip {dir}" + else: fmt"tar czf {dir}.tar.gz {dir}" + cpFile("../README.md", fmt"{dir}/README.md") + exec cmd + + +# begin Nimble config (version 2) +--noNimblePath +when withDir(thisDir(), system.fileExists("nimble.paths")): + include "nimble.paths" +# end Nimble config diff --git a/forge.nimble b/forge.nimble index 360002a..6cb03a6 100644 --- a/forge.nimble +++ b/forge.nimble @@ -7,26 +7,8 @@ bin = @["forge", "forgecc"] binDir = "bin" -requires "nim >= 2.0.0", - "cligen", - "https://github.com/daylinmorgan/bbansi#head" - - -import strformat - -task release, "build release assets": - version = (gorgeEx "git describe --tags --always --match 'v*'").output - exec &"forge release -v {version} -V" - -task bundle, "package build assets": - withDir "dist": - for dir in listDirs("."): - let cmd = if "windows" in dir: - &"7z a {dir}.zip {dir}" - else: - &"tar czf {dir}.tar.gz {dir}" - cpFile("../README.md", &"{dir}/README.md") - exec cmd - +requires "nim >= 2.0.0" +requires "cligen" +requires "https://github.com/daylinmorgan/hwylterm#HEAD" diff --git a/nimble.lock b/nimble.lock new file mode 100644 index 0000000..46c4d5d --- /dev/null +++ b/nimble.lock @@ -0,0 +1,26 @@ +{ + "version": 2, + "packages": { + "cligen": { + "version": "1.7.5", + "vcsRevision": "85daafd76b0104387f50ff3f75c829b4c2804412", + "url": "https://github.com/c-blake/cligen.git", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "f3ffe7329c8db755677d3ca377d02ff176cec8b1" + } + }, + "hwylterm": { + "version": "0.1.0", + "vcsRevision": "c2bcfd1f73dda97bd3e209c89e2abfe588f0977c", + "url": "https://github.com/daylinmorgan/hwylterm", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "1932229840c893c39acca0b50def19913678f5f0" + } + } + }, + "tasks": {} +} diff --git a/src/forge.nim b/src/forge.nim index a47183a..37701a1 100644 --- a/src/forge.nim +++ b/src/forge.nim @@ -1,5 +1,4 @@ import std/[os, osproc, sequtils, strformat, strutils, tables] - import forge/[config, utils, term, zig] proc genFlags(target: string, args: seq[string] = @[]): seq[string] = @@ -26,6 +25,7 @@ proc targets() = proc cc(target: string, dryrun: bool = false, nimble: bool = false, args: seq[string]) = ## compile with zig cc + zigExists() if args.len == 0: termErrQuit "expected additional arguments i.e. -- -d:release src/main.nim" @@ -64,6 +64,7 @@ proc release( ## default: ${name}-v${verison}-${target} ## ## if name or version are not specified they will be inferred from the local .nimble file + zigExists() let cfg = newConfig( target, @@ -125,33 +126,23 @@ proc release( when isMainModule: import cligen - zigExists() + import hwylterm/cli + hwylCli(clCfg) - const - customMulti = "Usage:\n $command {SUBCMD} [sub-command options & parameters]\n\nsubcommands:\n$subcmds" - vsn = staticExec "git describe --tags --always HEAD" - - - if clCfg.useMulti == "": clCfg.useMulti = customMulti - if clCfg.helpAttr.len == 0: - clCfg.helpAttr = {"cmd": "\e[1;36m", "clDescrip": "", "clDflVal": "\e[33m", - "clOptKeys": "\e[32m", "clValType": "\e[31m", "args": "\e[3m"}.toTable - clCfg.helpAttrOff = {"cmd": "\e[m", "clDescrip": "\e[m", "clDflVal": "\e[m", - "clOptKeys": "\e[m", "clValType": "\e[m", "args": "\e[m"}.toTable + let clUse* = $bb("$command $args\n${doc}[bold]Options[/]:\n$options") + const vsn = staticExec "git describe --tags --always HEAD" var vsnCfg = clCfg vsnCfg.version = vsn - dispatchMulti( ["multi", cf = vsnCfg], - [cc, help = { - "dryrun": "show command instead of executing", - "nimble": "use nimble as base command for compiling" + [cc, usage = clUse, help = { + "dryrun": "show command instead of executing", + "nimble": "use nimble as base command for compiling" }], - [targets], - [release, - help = { + [targets, usage = clUse], + [release, usage = clUse, help = { "target": "set target, may be repeated", "bin": "set bin, may be repeated", "dryrun": "show command instead of executing", @@ -160,6 +151,6 @@ when isMainModule: "config-file": "path to config", "no-config": "ignore config file" }, - short = {"verbose": 'V'} + short = {"verbose": 'V'} ] ) diff --git a/src/forge/config.nim b/src/forge/config.nim index c77cd82..1a49de2 100644 --- a/src/forge/config.nim +++ b/src/forge/config.nim @@ -19,19 +19,19 @@ proc showConfig*(c: ForgeConfig) = if args != "": result.add fmt" | " & $args.bb("faint") - addLine $fmt""" + addLine $bbfmt""" config = | [blue]nimble[/] {c.nimble} | [blue]outdir[/] {c.outdir} | [blue]format[/] {c.format} -| [blue]version[/] {c.version}""".bb +| [blue]version[/] {c.version}""" - addLine $"| [green]targets[/]:".bb + addLine $bb"| [green]targets[/]:" for target, args in c.targets: addLine addNameArgs(target, args) - addLine $"| [green]bins[/]:".bb + addLine $bb"| [green]bins[/]:" for bin, args in c.bins: addline addNameArgs(bin, args) @@ -41,8 +41,7 @@ proc loadConfigFile*( f: string, load_targets: bool, load_bins: bool - ): ForgeConfig = - +): ForgeConfig = let dict = loadConfig(f) # get the top level flags @@ -65,7 +64,7 @@ proc loadConfigFile*( proc inferName(s: string, nimbleFile: string): string = if s != "": return s - elif nimbleFile != "": + elif nimbleFile != "": return nimbleFile.rsplit(".", maxsplit = 1)[0] proc findNimbleFile(): string = @@ -112,7 +111,7 @@ proc newConfig*( nimble: bool, configFile: string, noConfig: bool - ): ForgeConfig = +): ForgeConfig = let nimbleFile = findNimbleFile() diff --git a/src/forge/term.nim b/src/forge/term.nim index 5512396..8d4b788 100644 --- a/src/forge/term.nim +++ b/src/forge/term.nim @@ -1,6 +1,6 @@ import std/strutils -import bbansi +import hwylterm let prefix = "[bold magenta]forge[/] [yellow]||[/] ".bb @@ -14,4 +14,4 @@ template termErrQuit*(args: varargs[string | BbString, `$`]) = termErr args quit 1 -export bbansi +export hwylterm