Compare commits
No commits in common. "release" and "v1.0.2" have entirely different histories.
|
@ -6,16 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to
|
and this project adheres to
|
||||||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [1.1.0] - 2024-01-19
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Support for comments (`#`) in parts files.
|
|
||||||
- Explicitly inherit paths from `PATH` environment variable.
|
|
||||||
- Ability to deduplicate output paths.
|
|
||||||
|
|
||||||
## [1.0.2] - 2023-12-05
|
## [1.0.2] - 2023-12-05
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Initial release.
|
- Initial release.
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
VERSION = 1.1.0
|
VERSION = 1.0.2
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
OS != uname -o
|
OS != uname -o
|
||||||
|
|
|
@ -35,7 +35,7 @@ Running the program with such a directory would yield the following result:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ pathsd paths.d/
|
$ pathsd paths.d/
|
||||||
export PATH="/Users/bilbo/opt/bin:/opt/homebrew/bin:/opt/homebrew/sbin":<paths inherited from $PATH>
|
export PATH="/Users/bilbo/opt/bin:/opt/homebrew/bin:/opt/homebrew/sbin":$PATH
|
||||||
```
|
```
|
||||||
|
|
||||||
You can specify multiple directories. They'll be processed one by one in the
|
You can specify multiple directories. They'll be processed one by one in the
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "1.1.0"
|
version = "1.0.2"
|
||||||
author = "Tomek Wójcik <contact@bthlabs.pl>"
|
author = "Tomek Wójcik <contact@bthlabs.pl>"
|
||||||
description = "pathsd by BTHLabs"
|
description = "pathsd by BTHLabs"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import std/[algorithm, dirs, envvars, logging, options, paths, strutils, syncio]
|
import std/[algorithm, dirs, logging, options, paths, strutils, syncio]
|
||||||
import strformat
|
import strformat
|
||||||
|
|
||||||
import commandant
|
import commandant
|
||||||
|
@ -9,7 +9,7 @@ type
|
||||||
output*: seq[string]
|
output*: seq[string]
|
||||||
errorCode*: ErrorCode
|
errorCode*: ErrorCode
|
||||||
|
|
||||||
const version = "1.1.0"
|
const version = "1.0.2"
|
||||||
const usage_string = """usage: pathsd [--version | --help] [-v | -q] [-s shell] search_path ..."""
|
const usage_string = """usage: pathsd [--version | --help] [-v | -q] [-s shell] search_path ..."""
|
||||||
const version_string = fmt"""pathsd {version}"""
|
const version_string = fmt"""pathsd {version}"""
|
||||||
const help_string = fmt"""pathsd {version} by BTHLabs
|
const help_string = fmt"""pathsd {version} by BTHLabs
|
||||||
|
@ -19,7 +19,6 @@ Usage:
|
||||||
pathsd [options] search_path ...
|
pathsd [options] search_path ...
|
||||||
Options:
|
Options:
|
||||||
-s --shell target shell (defaults to bash)
|
-s --shell target shell (defaults to bash)
|
||||||
-d --dedupe deduplicate the final paths
|
|
||||||
-v --verbose turn debugging messages on
|
-v --verbose turn debugging messages on
|
||||||
-q --quiet supress all logging messages
|
-q --quiet supress all logging messages
|
||||||
--version show the version
|
--version show the version
|
||||||
|
@ -53,8 +52,7 @@ proc readPart(path: Path): seq[string] =
|
||||||
try:
|
try:
|
||||||
var line: string = readLine(pathFile)
|
var line: string = readLine(pathFile)
|
||||||
while line != "":
|
while line != "":
|
||||||
if line.startsWith("#") == false:
|
result.add(line)
|
||||||
result.add(line)
|
|
||||||
line = readLine(pathFile)
|
line = readLine(pathFile)
|
||||||
except EOFError as exception:
|
except EOFError as exception:
|
||||||
discard
|
discard
|
||||||
|
@ -64,7 +62,7 @@ proc readPart(path: Path): seq[string] =
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
proc main*(searchPaths: seq[string], envParts: seq[string], dedupe: bool): MainResult =
|
proc main*(searchPaths: seq[string]): MainResult =
|
||||||
var parts: seq[string] = @[]
|
var parts: seq[string] = @[]
|
||||||
|
|
||||||
logger.log(lvlDebug, fmt"Processing search paths: {searchPaths}")
|
logger.log(lvlDebug, fmt"Processing search paths: {searchPaths}")
|
||||||
|
@ -85,16 +83,6 @@ proc main*(searchPaths: seq[string], envParts: seq[string], dedupe: bool): MainR
|
||||||
for partPath in partPaths:
|
for partPath in partPaths:
|
||||||
parts = parts & readPart(partPath)
|
parts = parts & readPart(partPath)
|
||||||
|
|
||||||
parts = parts & envParts
|
|
||||||
|
|
||||||
if dedupe == true:
|
|
||||||
var dedupedParts: seq[string] = @[]
|
|
||||||
for part in parts:
|
|
||||||
if dedupedParts.contains(part) == false:
|
|
||||||
dedupedParts.add(part)
|
|
||||||
|
|
||||||
parts = dedupedParts
|
|
||||||
|
|
||||||
return MainResult(output: parts, errorCode: QuitSuccess)
|
return MainResult(output: parts, errorCode: QuitSuccess)
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,7 +92,6 @@ when isMainModule:
|
||||||
commandant.option(shell, string, "shell", "s", "bash")
|
commandant.option(shell, string, "shell", "s", "bash")
|
||||||
flag(verbose, "verbose", "v")
|
flag(verbose, "verbose", "v")
|
||||||
flag(quiet, "quiet", "q")
|
flag(quiet, "quiet", "q")
|
||||||
flag(dedupe, "dedupe", "d")
|
|
||||||
exitoption("help", "h", help_string, QuitFailure)
|
exitoption("help", "h", help_string, QuitFailure)
|
||||||
exitoption("version", "", version_string, QuitFailure)
|
exitoption("version", "", version_string, QuitFailure)
|
||||||
errorproc(handleCommandantError)
|
errorproc(handleCommandantError)
|
||||||
|
@ -117,11 +104,7 @@ when isMainModule:
|
||||||
|
|
||||||
logger.levelThreshold = loggerLevel
|
logger.levelThreshold = loggerLevel
|
||||||
|
|
||||||
var envParts: seq[string] = @[]
|
var mainResult = main(searchPaths)
|
||||||
var envPath = envvars.getEnv("PATH")
|
|
||||||
envParts = envPath.split(":")
|
|
||||||
|
|
||||||
var mainResult = main(searchPaths, envParts, dedupe)
|
|
||||||
|
|
||||||
if mainResult.output != @[] and mainResult.errorCode == QuitSuccess:
|
if mainResult.output != @[] and mainResult.errorCode == QuitSuccess:
|
||||||
var output: string = ""
|
var output: string = ""
|
||||||
|
@ -129,7 +112,7 @@ when isMainModule:
|
||||||
case shell
|
case shell
|
||||||
of "bash":
|
of "bash":
|
||||||
let pathComponents = join(mainResult.output, ":")
|
let pathComponents = join(mainResult.output, ":")
|
||||||
output = fmt"""export PATH="{pathComponents}""""
|
output = fmt"""export PATH="{pathComponents}":$PATH"""
|
||||||
|
|
||||||
if output != "":
|
if output != "":
|
||||||
echo(output)
|
echo(output)
|
||||||
|
|
1
tests/fixtures/paths.d/01-bilbo
vendored
1
tests/fixtures/paths.d/01-bilbo
vendored
|
@ -1,2 +1 @@
|
||||||
/Users/bilbo/opt/bin
|
/Users/bilbo/opt/bin
|
||||||
#/Users/bilbo/.local/bin
|
|
||||||
|
|
|
@ -7,17 +7,13 @@ suite "Test main() proc":
|
||||||
setup:
|
setup:
|
||||||
const fixturesPath = Path(currentSourcePath) / Path("..") / Path("..") / Path("fixtures")
|
const fixturesPath = Path(currentSourcePath) / Path("..") / Path("..") / Path("fixtures")
|
||||||
const pathsdFixturePath = fixturesPath / Path("paths.d")
|
const pathsdFixturePath = fixturesPath / Path("paths.d")
|
||||||
const envParts = @["/usr/local/bin", "/usr/bin"]
|
const expectedOutput = @["/Users/bilbo/opt/bin", "/opt/homebrew/bin", "/opt/homebrew/sbin"]
|
||||||
const expectedOutput = @[
|
|
||||||
"/Users/bilbo/opt/bin", "/opt/homebrew/bin", "/opt/homebrew/sbin",
|
|
||||||
"/usr/local/bin", "/usr/bin",
|
|
||||||
]
|
|
||||||
|
|
||||||
pathsd.logger.levelThreshold = lvlNone
|
pathsd.logger.levelThreshold = lvlNone
|
||||||
|
|
||||||
test "Test happy path":
|
test "Test happy path":
|
||||||
# When
|
# When
|
||||||
var mainResult = pathsd.main(@[pathsdFixturePath.string], envParts, false)
|
var mainResult = pathsd.main(@[pathsdFixturePath.string])
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
check mainResult.output == expectedOutput
|
check mainResult.output == expectedOutput
|
||||||
|
@ -25,28 +21,10 @@ suite "Test main() proc":
|
||||||
|
|
||||||
test "Test skipping search paths that don't exist":
|
test "Test skipping search paths that don't exist":
|
||||||
# When
|
# When
|
||||||
var mainResult = pathsd.main(
|
var mainResult = pathsd.main(@[
|
||||||
@[
|
pathsdFixturePath.string,
|
||||||
pathsdFixturePath.string,
|
(fixturesPath / Path("idontexist")).string,
|
||||||
(fixturesPath / Path("idontexist")).string,
|
])
|
||||||
],
|
|
||||||
envParts,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Then
|
|
||||||
check mainResult.output == expectedOutput
|
|
||||||
|
|
||||||
test "Test dedupe":
|
|
||||||
# Given
|
|
||||||
const localEnvParts = @[
|
|
||||||
"/usr/local/bin", "/usr/bin", "/Users/bilbo/opt/bin",
|
|
||||||
]
|
|
||||||
|
|
||||||
# When
|
|
||||||
var mainResult = pathsd.main(
|
|
||||||
@[pathsdFixturePath.string], localEnvParts, true,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
check mainResult.output == expectedOutput
|
check mainResult.output == expectedOutput
|
||||||
|
|
Loading…
Reference in New Issue
Block a user