Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions src/main.tr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from std.io import File
from std.os import OS, Process, Env
from cli import parse_args, print_usage, CliArgs
from manifest import Manifest, find_manifest
from manifest import Manifest
from lockfile import Lockfile, LockedPkg
from semver import Version
from source import parse_source
Expand Down Expand Up @@ -39,14 +39,12 @@ def main(argv: Vec[str]):

# All remaining commands need a project root with taupkg.toml
mut cwd = OS.cwd()
mut manifest_path = find_manifest(cwd)
if manifest_path.len() == 0:
manifest_path = path_join(cwd, "taupkg.toml")
if not File.file_exists(manifest_path):
print("error: no taupkg.toml found. Run `taupkg init` first.")
return 1

mut project_root = path_join(manifest_path, "..")
project_root = find_project_root(cwd)
mut manifest_path = path_join(project_root, "taupkg.toml")
if not File.file_exists(manifest_path):
print("error: no taupkg.toml found. Run `taupkg init` first.")
return 1

mut manifest = Manifest.load(manifest_path)
if not manifest.is_valid():
print("error: invalid taupkg.toml -- 'name' and 'version' are required")
Expand Down Expand Up @@ -421,6 +419,27 @@ def cmd_publish(manifest: Manifest, manifest_path: str, project_root: str, verbo

# -- internal helpers -----------------------------------------------------------


# Finds the project root directory
pub def find_project_root(start_dir: str) -> str:
mut dir = start_dir
mut limit = 16
while limit > 0:
mut candidate = dir + "/taupkg.toml"
if File.file_exists(candidate):
return dir
mut pos = dir.len() - 1
while pos > 0:
mut c = dir.char_at(pos)
if c == 47 or c == 92:
break
pos = pos - 1
if pos <= 0:
return ""
dir = dir.slice(0, pos)
limit = limit - 1
return ""

# Re-parse the manifest TOML to get dep names as a Vec[str].
# This exists because Map has no key-iteration; we parse the raw file.
def _collect_dep_names(manifest: Manifest, project_root: str) -> Vec[str]:
Expand Down
20 changes: 0 additions & 20 deletions src/manifest.tr
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,3 @@ extend Manifest:
m.sources = src_sec.keys

return m


pub def find_manifest(start_dir: str) -> str:
mut dir = start_dir
mut limit = 16
while limit > 0:
mut candidate = dir + "/taupkg.toml"
if File.file_exists(candidate):
return candidate
mut pos = dir.len() - 1
while pos > 0:
mut c = dir.char_at(pos)
if c == 47 or c == 92:
break
pos = pos - 1
if pos <= 0:
return ""
dir = dir.slice(0, pos)
limit = limit - 1
return ""
Loading