1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
//LICENSE
//LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
//LICENSE
//LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc. <contact@pgcentral.org>
//LICENSE
//LICENSE All rights reserved.
//LICENSE
//LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
use crate::CommandExecute;
use pgrx_pg_config::Pgrx;
use std::borrow::Cow;
/// Provides information about pgrx-managed development environment
#[derive(clap::Args, Debug)]
#[clap(author)]
pub(crate) struct Info {
#[clap(subcommand)]
command: Subcommand,
}
#[derive(clap::Subcommand, Debug)]
pub(crate) enum Subcommand {
/// Print path to a base version of Postgres build
///
/// cargo pgrx info path 15 #=> ~/.pgrx/15.2/pgrx-install
Path {
/// Postgres version (12, 13, 14, 15...)
pg_ver: String,
},
/// Print path to pg_config for a base version of Postgres
///
/// cargo pgrx info pg-config 15 #=> ~/.pgrx/15.2/pgrx-install/bin/pg_config
PgConfig {
/// Postgres version (12, 13, 14, 15...)
pg_ver: String,
},
/// Print specific version for a base Postgres version
///
/// cargo pgrx info version 15 #=> 15.2
Version {
/// Postgres version (12, 13, 14, 15...)
pg_ver: String,
},
}
impl CommandExecute for Info {
#[tracing::instrument(level = "error", skip(self))]
fn execute(self) -> eyre::Result<()> {
let config = Pgrx::from_config()?;
match self.command {
Subcommand::Path { ref pg_ver } => {
println!(
"{}",
config
.get(&version(pg_ver))?
.parent_path()
.parent()
.ok_or(eyre::Error::msg("can't get path"))?
.display()
);
}
Subcommand::PgConfig { ref pg_ver } => {
println!(
"{}",
config
.get(&version(pg_ver))?
.path()
.ok_or(eyre::Error::msg("can't get path"))?
.display()
);
}
Subcommand::Version { ref pg_ver } => {
println!("{}", config.get(&version(pg_ver))?.version()?);
}
}
Ok(())
}
}
fn version(ver: &str) -> Cow<'_, str> {
if ver.starts_with("pg") { Cow::Borrowed(ver) } else { Cow::Owned(format!("pg{ver}")) }
}