Skip to content

Commit

Permalink
0.0.24: add araq's 🔱
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Dec 1, 2019
1 parent 3cc10c5 commit d1789d7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ much as possible.
$ nimble install https://github.com/disruptek/nimph
```

## Details
## Usage

It's worth noting that you can run `nimph` from anywhere in your project tree;
it will simply search upwards until it finds a `.nimble` file and act as if you
Expand Down Expand Up @@ -129,6 +129,21 @@ adjusting path settings in the project's `nim.cfg`, and similar housekeeping.
$ nimph doctor
👌bot version 0.0.11 lookin' good
```
### Fork

The `fork` subcommand is used to fork an installed dependency in your GitHub
account and add a new git `origin` remote pointing at your new fork. The
original `origin` remote is renamed to `upstream` by default. These constants
may be easily changed; see **Hacking** below.

This allows you to quickly move from merely testing a package to improving it
and sharing your work upstream.

```
$ nimph fork npeg
🍴forking npeg-#54ed418e80f1e1b14133ed383b9c585b320a66cf
🔱https://github.com/disruptek/npeg
```

### Path

Expand Down Expand Up @@ -169,6 +184,9 @@ more spam.
Interesting procedures are exported so that you can exploit them in your own
projects.

Compilation flags to adjust output colors/styling/emojis are found in the
project's `nimph.nim.cfg`.

## Documentation

See [the documentation for the nimph module](https://disruptek.github.io/nimph/nimph.html) as generated directly from the source.
Expand Down
2 changes: 1 addition & 1 deletion nimph.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.0.23"
version = "0.0.24"
author = "disruptek"
description = "nim package handler from the future"
license = "MIT"
Expand Down
53 changes: 48 additions & 5 deletions src/nimph.nim
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,48 @@ proc pather*(names: seq[string]; log_level = logLevel): int =
if found.isSome:
echo found.get
else:
error &"couldn't find `{name}` among our installed dependencies"
echo "" # a failed find produces empty output
result = 1 # and sets the return code to nonzero

proc forker*(names: seq[string]; log_level = logLevel): int =
# user's choice, our default
setLogFilter(log_level)

var
project: Project
group = newDependencyGroup(flags = {Flag.Quiet})
setupLocalProject(project)

if not project.resolveDependencies(group):
notice &"unable to resolve all dependencies for {project}"

for name in names.items:
let found = group.projectForName(name)
if found.isNone:
error &"couldn't find `{name}` among our installed dependencies"
result = 1
continue
let
child = found.get
fork = child.forkTarget
if not fork.ok:
error fork.why
result = 1
continue
info &"🍴forking {child}"
let forked = waitfor forkHub(fork.owner, fork.repo)
if forked.isNone:
result = 1
continue
fatal &"🔱{forked.get.web}"
if child.dist == Git:
let name = defaultRemote
if not child.promoteFork(forked.get, defaultRemote):
notice &"unable to promote new fork to {name}"
else:
{.warning: "optionally upgrade a gitless install to clone".}

proc cloner*(args: seq[string]; log_level = logLevel): int =
# user's choice, our default
setLogFilter(log_level)
Expand Down Expand Up @@ -178,6 +217,7 @@ when isMainModule:
scClone = "clone"
scNimble = "nimble"
scPath = "path"
scFork = "fork"
scVersion = "--version"
scHelp = "--help"

Expand All @@ -192,7 +232,7 @@ when isMainModule:
else:
clCfg.version = "(unknown version)"

# setup some dispatches for various subcommands
# setup some dispatchers for various subcommands
dispatchGen(searcher, cmdName = $scSearch, dispatchName = "run" & $scSearch,
doc="search github for packages")
dispatchGen(fixer, cmdName = $scDoctor, dispatchName = "run" & $scDoctor,
Expand All @@ -201,12 +241,14 @@ when isMainModule:
doc="add a package to the env")
dispatchGen(pather, cmdName = $scPath, dispatchName = "run" & $scPath,
doc="fetch package path(s) by import name(s)")
dispatchGen(forker, cmdName = $scFork, dispatchName = "run" & $scFork,
doc="fork a package to your GitHub profile")
dispatchGen(nimbler, cmdName = $scNimble, dispatchName = "run" & $scNimble,
doc="Nimble handles other subcommands (with a proper nimbleDir)")

const
# these are our subcommands that we want to include in help
dispatchees = [runsearch, runclone, rundoctor, runpath]
dispatchees = [runsearch, runclone, rundoctor, runpath, runfork]

# these are nimble subcommands that we don't need to warn about
passthrough = ["install", "uninstall", "build", "test", "doc", "dump",
Expand All @@ -227,6 +269,7 @@ when isMainModule:
scDoctor: rundoctor,
scClone: runclone,
scPath: runpath,
scFork: runfork,
#scNimble: runnimble,
}.toTable

Expand Down Expand Up @@ -256,9 +299,6 @@ when isMainModule:
# take action according to the subcommand
try:
case sub:
of scSearch, scDoctor, scClone, scPath:
# invoke the appropriate dispatcher
quit dispatchers[sub](cmdline = params[1..^1])
of scNimble:
# invoke nimble with the original parameters
quit runnimble(cmdline = params)
Expand All @@ -280,6 +320,9 @@ when isMainModule:
# produce help for nimble subcommands
discard runnimble(cmdline = @["--help"], prefix = " ",
usage = nimbleUse)
else:
# invoke the appropriate dispatcher
quit dispatchers[sub](cmdline = params[1..^1])
except HelpOnly:
discard
quit 0

0 comments on commit d1789d7

Please sign in to comment.