Skip to content

Commit cfb5874

Browse files
authored
Merge pull request #1175 from pkgxdev/chdir
--chdir/-C
2 parents 1822b08 + 93635c1 commit cfb5874

File tree

6 files changed

+47
-10
lines changed

6 files changed

+47
-10
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ jobs:
195195
PKGX_DIR: ${{ github.workspace }}/pkgx
196196
PKGX_DIST_URL: https://dist.pkgx.dev
197197

198+
- name: --chdir
199+
run: |
200+
d=$(realpath $(mktemp -d))
201+
test $(pwd) != $d
202+
test $(pkgx -C $d -- pwd) = $d
203+
test $(pkgx --chdir $d -- pwd) = $d
204+
198205
- name: generate coverage
199206
run: |
200207
pkgx +llvm.org -- llvm-profdata merge -sparse $(find . -name default_\*.prof\*) -o default.profdata

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
> [!NOTE]
88
>
9-
> You want your tools to *just work* and we want that too. We pride ourselves
9+
> You want your tools to _just work_ and we want that too. We pride ourselves
1010
> on packaging things as well as possible because we want you to change the
1111
> world with what you build and not have to worry about the rest.
1212
@@ -74,7 +74,7 @@ Python 2.7.18
7474
> - libm.so.6 (provided by glibc)
7575
> - libgcc_s.so.1 (provided by libgcc)
7676
> - libpthread.so.0 (provided by glibc)
77-
> - libc.so.6 (this *is* glibc)
77+
> - libc.so.6 (this _is_ glibc)
7878
> - ld-linux-x86-64.so.2 (provided by the kernel, you get this for free)
7979
>
8080
> `libgcc` is built as part of the GCC distribution and usually is split out

crates/cli/src/args.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct Flags {
1414
pub version_n_continue: bool,
1515
pub shebang: bool,
1616
pub sync: bool,
17+
pub chdir: Option<String>,
1718
}
1819

1920
pub struct Args {
@@ -36,9 +37,11 @@ pub fn parse() -> Args {
3637
let mut version_n_continue = false;
3738
let mut shebang = false;
3839
let mut sync = false;
40+
let mut chdir = None;
3941
let json_latest_v: isize = 2;
4042

41-
for arg in std::env::args().skip(1) {
43+
let mut args_iter = std::env::args().skip(1);
44+
while let Some(arg) = args_iter.next() {
4245
if collecting_args {
4346
args.push(arg);
4447
} else if arg.starts_with('+') {
@@ -59,6 +62,7 @@ pub fn parse() -> Args {
5962
}
6063
json = Some(2);
6164
}
65+
"--chdir" | "--cd" => chdir = args_iter.next(),
6266
"--json=v1" => json = Some(1),
6367
"--json=v2" => json = Some(2),
6468
"--silent" => silent = true,
@@ -105,6 +109,7 @@ pub fn parse() -> Args {
105109
'v' => version_n_continue = true,
106110
'!' => shebang = true,
107111
'Q' => mode = Mode::Query,
112+
'C' => chdir = args_iter.next(),
108113
_ => panic!("unknown argument: -{}", c),
109114
}
110115
}
@@ -127,6 +132,7 @@ pub fn parse() -> Args {
127132
quiet,
128133
version_n_continue,
129134
sync,
135+
chdir,
130136
},
131137
}
132138
}

crates/cli/src/help.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ modes:
2828
$ pkgx --version
2929
3030
flags:
31-
-q, --quiet # suppress brief informational messages
32-
-qq, --silent # no chat. no errors. just execute.
33-
-v # print version and continue
34-
--sync # sync first (note: rarely if ever needed)
35-
-j,--json=v2 # output JSON (if sensible)
31+
-q, --quiet # suppress brief informational messages
32+
-qq, --silent # no chat. no errors. just execute.
33+
-j, --json=v2 # output JSON (if sensible)
34+
-C, --chdir <d> # change directory first
35+
--sync # sync first (note: rarely if ever needed)
36+
-v # print version and continue
3637
3738
more:
3839
$ OPEN https://docs.pkgx.sh

crates/cli/src/main.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2424
find_program,
2525
} = args::parse();
2626

27+
if let Some(dir) = &flags.chdir {
28+
std::env::set_current_dir(dir)?;
29+
}
30+
2731
if flags.version_n_continue {
28-
eprintln!("pkgx {}", env!("CARGO_PKG_VERSION"));
32+
print_version(flags.json.is_some());
2933
}
3034

3135
match mode {
@@ -34,7 +38,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3438
Ok(())
3539
}
3640
args::Mode::Version => {
37-
println!("pkgx {}", env!("CARGO_PKG_VERSION"));
41+
print_version(flags.json.is_some());
3842
Ok(())
3943
}
4044
args::Mode::Query => {
@@ -96,3 +100,14 @@ async fn setup(
96100

97101
Ok((conn, did_sync, config, spinner))
98102
}
103+
104+
fn print_version(json: bool) {
105+
if !json {
106+
eprintln!("pkgx {}", env!("CARGO_PKG_VERSION"));
107+
} else {
108+
eprintln!(
109+
"{{\"program\": \"pkgx\", \"version\": \"{}\"}}",
110+
env!("CARGO_PKG_VERSION")
111+
);
112+
}
113+
}

docs/pkgx.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ standardized so we offer some `mash` scripts to help.
190190
191191
Longer term we will make a tool `pkgq` to help with these operations.
192192
193+
### Listing Outdated Packages
194+
195+
```sh
196+
pkgx mash outdated
197+
```
198+
193199
### Upgrading Packages
194200
195201
`pkgx foo` executes the latest version of `foo` that is _downloaded_. To ensure
@@ -201,6 +207,8 @@ updating: /Users/mxcl/.pkgx/python.org/v3.11.11
201207
# snip…
202208
```
203209
210+
You can specify args to upgrade only specific packages.
211+
204212
### Pruning Older Versions of Packages
205213
206214
The `pkgx` download cache can get large over time. To prune older versions:

0 commit comments

Comments
 (0)