Skip to content

Commit 5f2511a

Browse files
committed
imp(cli): accept argument for exec command
1 parent c0b9bab commit 5f2511a

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

pyroscope_cli/cli/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,14 @@ enum Commands {
166166
long_about = None,
167167
)]
168168
Exec {
169-
/// The command to execute
170-
#[clap(required = true)]
169+
#[clap(
170+
required = true,
171+
name = "command",
172+
value_name = "COMMAND",
173+
help = "command to execute",
174+
takes_value = true,
175+
multiple_values = true
176+
)]
171177
command: Option<String>,
172178
#[clap(
173179
name = "application_name",

pyroscope_cli/core/src/commands.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ pub fn exec() -> Result<()> {
1818
let command = AppConfig::get::<Option<String>>("command")?
1919
.ok_or_else(|| Error::new("command unwrap failed"))?;
2020

21+
let command_args = AppConfig::get::<Option<String>>("command_args")?
22+
.ok_or_else(|| Error::new("command unwrap failed"))?;
23+
2124
// Get UID
2225
let uid = AppConfig::get::<Option<u32>>("user_name").unwrap_or(None);
2326
// Get GID
2427
let gid = AppConfig::get::<Option<u32>>("group_name").unwrap_or(None);
2528

2629
// Create new executor and run it
27-
let executor = Executor::new(command.as_ref(), "", uid, gid).run()?;
30+
let executor = Executor::new(command.as_ref(), command_args.as_ref(), uid, gid).run()?;
2831

2932
// Set PID
3033
AppConfig::set("pid", executor.get_pid()?.to_string().as_str())?;

pyroscope_cli/utils/src/app_config.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use config::{Config, Environment};
22
use lazy_static::lazy_static;
33
use serde::{Deserialize, Serialize};
4-
use std::ops::Deref;
5-
use std::path::Path;
64
use std::sync::RwLock;
5+
use std::{ops::Deref, path::Path};
76

87
use super::error::Result;
98
use crate::types::{LogLevel, Spy};
@@ -35,6 +34,7 @@ pub struct AppConfig {
3534
pub user_name: Option<u32>,
3635
pub group_name: Option<u32>,
3736
pub command: Option<String>,
37+
pub command_args: Option<String>,
3838
}
3939

4040
impl AppConfig {
@@ -134,8 +134,26 @@ impl AppConfig {
134134
// Exec Command
135135
if let Some(sub_exec) = args.subcommand_matches("exec") {
136136
if sub_exec.is_present("command") {
137-
if let Some(command) = sub_exec.value_of("command") {
138-
AppConfig::set("command", command)?;
137+
if let Some(command) = sub_exec.values_of("command") {
138+
// Get First element of command
139+
let cmd = command
140+
.clone()
141+
.collect::<Vec<&str>>()
142+
.first()
143+
.unwrap_or(&String::from("").as_str())
144+
.to_string();
145+
AppConfig::set("command", &cmd)?;
146+
147+
// Get rest of command
148+
let command_args = command
149+
.collect::<Vec<&str>>()
150+
.iter()
151+
.skip(1)
152+
.map(|s| s.to_string())
153+
.collect::<Vec<String>>()
154+
.join(" ");
155+
156+
AppConfig::set("command_args", &command_args)?;
139157
}
140158
}
141159
if sub_exec.is_present("log_level") {

0 commit comments

Comments
 (0)