Skip to content

Commit 6c001d0

Browse files
Download challenges to correct location independent of current directory
1 parent 0a8fd6d commit 6c001d0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

toolkit.nu

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
#!/usr/bin/env nu
22

33
def --wrapped main [...rest] {
4-
nu -c $'use toolkit.nu; toolkit ($rest | str join (char space))'
4+
const pathToSelf = path self
5+
let nameOfSelf = $pathToSelf | path parse | get stem
6+
if $rest in [ [-h] [--help] ] {
7+
^$nu.current-exe -c $'use ($pathToSelf); scope modules | where name == ($nameOfSelf) | get 0.commands.name'
8+
} else {
9+
^$nu.current-exe -c $'use ($pathToSelf); ($nameOfSelf) ($rest | str join (" "))'
10+
}
511
}
612

7-
export def pull [problemNumber] {
13+
export def download-challenge [problemNumber] {
14+
const path_to_src_folder = [(path self) .. project_euler] | path join
815
let file = http get $"https://projecteuler.net/problem=($problemNumber)"
916
| parse '<title>#{number} {title} - Project Euler</title>'
1017
| get title.0
1118
| str snake-case
1219
| {
13-
parent: project_euler
20+
parent: $path_to_src_folder
1421
stem: $"test_pe($problemNumber)_($in)"
1522
extension: py
1623
}

0 commit comments

Comments
 (0)