Skip to content

Commit dd18fbc

Browse files
committed
Add init operation for 30 package managers
Add Init() to the Manager interface and CapInit capability. Adds init command definitions to 30 of 36 managers that support non-interactive project initialization. Managers without init: brew, cpanm, gem, maven, pip, sbt (global installers or interactive-only init).
1 parent 15d8a75 commit dd18fbc

33 files changed

Lines changed: 243 additions & 3 deletions

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A Go library that wraps package manager CLIs behind a common interface. Part of
44

55
## What it does
66

7-
Translates generic operations (install, add, remove, list, outdated, update, vendor, resolve) into the correct CLI commands for each package manager. Define what you want to do once, and the library figures out the right command for npm, bundler, cargo, go, or any other supported manager.
7+
Translates generic operations (init, install, add, remove, list, outdated, update, vendor, resolve) into the correct CLI commands for each package manager. Define what you want to do once, and the library figures out the right command for npm, bundler, cargo, go, or any other supported manager.
88

99
```go
1010
translator := managers.NewTranslator()
@@ -83,7 +83,7 @@ cmd, _ = translator.BuildCommand("bundler", "add", managers.CommandInput{
8383
| helm | helm | Chart.lock |
8484
| brew | homebrew | - |
8585

86-
Most managers support: install, add, remove, list, outdated, update, resolve. Some also support vendor and path. Some managers (maven, gradle, sbt, lein) have limited CLI support for add/remove operations.
86+
Most managers support: init, install, add, remove, list, outdated, update, resolve. Some also support vendor and path. Some managers (maven, gradle, sbt, lein) have limited CLI support for add/remove operations. A few global installers (brew, gem, cpanm) and managers with interactive-only init (maven, pip, sbt) do not have init support.
8787

8888
## Installation
8989

@@ -211,6 +211,7 @@ Built-in policies include AllowAllPolicy, DenyAllPolicy, and PackageBlocklistPol
211211

212212
| Operation | Description |
213213
|-----------|-------------|
214+
| `init` | Initialize a new project with manifest file |
214215
| `install` | Install dependencies from lockfile |
215216
| `add` | Add a new dependency |
216217
| `remove` | Remove a dependency |
@@ -229,6 +230,18 @@ Built-in policies include AllowAllPolicy, DenyAllPolicy, and PackageBlocklistPol
229230
| `frozen` | Fail if lockfile would change (CI mode) |
230231
| `json` | Output in JSON format (where supported) |
231232

233+
### Initializing projects
234+
235+
The `init` operation creates a new project with the package manager's default manifest file. This is useful for creating temporary projects for dependency resolution or scaffolding new projects.
236+
237+
```go
238+
manager, _ := managers.Detect("/path/to/empty/dir")
239+
result, _ := manager.Init(ctx)
240+
// Creates package.json (npm), Gemfile (bundler), Cargo.toml (cargo), etc.
241+
```
242+
243+
**Managers with init support:** npm, pnpm, yarn, bun, bundler, cargo, gomod, uv, poetry, deno, composer, swift, pub, mix, nuget, gradle, helm, conan, conda, stack, lein, rebar3, cabal, cocoapods, nimble, opam, luarocks, shards, vcpkg, renv
244+
232245
### Getting package paths
233246

234247
The `path` operation returns the filesystem path to an installed package, useful for source exploration or editor integration:

definitions/bun.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ detection:
1818
priority: 25 # Higher than npm/yarn/pnpm when bun lockfile present
1919

2020
commands:
21+
init:
22+
base: [init, -y]
23+
exit_codes:
24+
0: success
25+
1: error
26+
2127
install:
2228
base: [install]
2329
flags:
@@ -92,6 +98,7 @@ commands:
9298
1: error
9399

94100
capabilities:
101+
- init
95102
- install
96103
- install_frozen
97104
- add

definitions/bundler.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ version_detection:
1818
pattern: '(\d+\.\d+\.\d+)'
1919

2020
commands:
21+
init:
22+
base: [init]
23+
exit_codes:
24+
0: success
25+
1: error
26+
2127
install:
2228
base: [install]
2329
flags:
@@ -125,6 +131,7 @@ commands:
125131
1: error
126132

127133
capabilities:
134+
- init
128135
- install
129136
- install_frozen
130137
- add

definitions/cabal.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ version_detection:
1616
pattern: 'cabal-install version (\d+\.\d+\.\d+)'
1717

1818
commands:
19+
init:
20+
base: [init, -n, -p, resolve-tmp]
21+
exit_codes:
22+
0: success
23+
1: error
24+
1925
install:
2026
base: [build, --only-dependencies]
2127
flags:
@@ -63,6 +69,7 @@ commands:
6369
1: error
6470

6571
capabilities:
72+
- init
6673
- install
6774
- list
6875
- outdated

definitions/cargo.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ version_detection:
1818
pattern: 'cargo (\d+\.\d+\.\d+)'
1919

2020
commands:
21+
init:
22+
base: [init, --lib]
23+
exit_codes:
24+
0: success
25+
1: error
26+
2127
# cargo fetch downloads dependencies without building
2228
# cargo build would also work but does more than just install
2329
install:
@@ -129,6 +135,7 @@ commands:
129135
1: error
130136

131137
capabilities:
138+
- init
132139
- install
133140
- install_frozen
134141
- add

definitions/cocoapods.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ detection:
1717
priority: 10
1818

1919
commands:
20+
init:
21+
base: [init]
22+
exit_codes:
23+
0: success
24+
1: error
25+
2026
install:
2127
base: [install]
2228
flags:

definitions/composer.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ detection:
1717
priority: 10
1818

1919
commands:
20+
init:
21+
base: [init, -n]
22+
default_flags: [--name, resolve/tmp]
23+
exit_codes:
24+
0: success
25+
1: error
26+
2027
install:
2128
base: [install]
2229
flags:
@@ -91,6 +98,7 @@ commands:
9198
1: error
9299

93100
capabilities:
101+
- init
94102
- install
95103
- add
96104
- add_dev

definitions/conan.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ version_detection:
1616
pattern: 'Conan version (\d+\.\d+\.\d+)'
1717

1818
commands:
19+
init:
20+
base: [new, resolve-tmp, -d, basic]
21+
exit_codes:
22+
0: success
23+
1: error
24+
1925
install:
2026
base: [install, .]
2127
flags:
@@ -82,6 +88,7 @@ commands:
8288
1: error
8389

8490
capabilities:
91+
- init
8592
- install
8693
- add
8794
- remove

definitions/conda.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ version_detection:
1616
pattern: 'conda (\d+\.\d+\.\d+)'
1717

1818
commands:
19+
init:
20+
base: [create, -n, resolve-tmp, --yes]
21+
exit_codes:
22+
0: success
23+
1: error
24+
1925
install:
2026
base: [install, --yes]
2127
base_overrides:
@@ -96,6 +102,7 @@ commands:
96102
1: error
97103

98104
capabilities:
105+
- init
99106
- install
100107
- install_frozen
101108
- add

definitions/deno.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ version_detection:
1616
pattern: 'deno (\d+\.\d+\.\d+)'
1717

1818
commands:
19+
init:
20+
base: [init]
21+
exit_codes:
22+
0: success
23+
1: error
24+
1925
install:
2026
base: [install]
2127
flags:
@@ -86,6 +92,7 @@ commands:
8692
1: error
8793

8894
capabilities:
95+
- init
8996
- install
9097
- install_frozen
9198
- add

0 commit comments

Comments
 (0)