Skip to content

Commit

Permalink
Make exec command find first session with address
Browse files Browse the repository at this point in the history
  • Loading branch information
DervexDev committed May 8, 2024
1 parent 5655adc commit 0fa65ac
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## [Unreleased]

### Changed

- `exec` command now looks for the first session with address instead of failing

## [2.0.5] - 2024-05-06

### Fixed
Expand Down
9 changes: 8 additions & 1 deletion src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ impl Exec {
// TODO: Implement standalone mode
argon_error!("Standalone mode is not implemented yet!");
} else if let Some(session) = sessions::get(self.session, self.host, self.port)? {
if let Some(address) = session.get_address() {
let address = session.get_address().or_else(|| {
sessions::get_all()
.unwrap_or_default()
.into_iter()
.find_map(|(_, session)| session.get_address())
});

if let Some(address) = address {
let url = format!("{}/exec", address);

let body = rmp_serde::to_vec(&Request {
Expand Down
8 changes: 4 additions & 4 deletions src/cli/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ impl Stop {
if self.list {
let sessions = sessions::get_all()?;

if sessions.is_none() {
if sessions.is_empty() {
argon_warn!("There are no running sessions");
return Ok(());
}

let mut table = Table::new();
table.set_header(vec!["ID", "Host", "Port", "PID"]);

for (id, session) in sessions.unwrap() {
for (id, session) in sessions {
let port = if let Some(port) = session.port {
port.to_string()
} else {
Expand All @@ -65,12 +65,12 @@ impl Stop {
if self.all {
let sessions = sessions::get_all()?;

if sessions.is_none() {
if sessions.is_empty() {
argon_warn!("There are no running sessions");
return Ok(());
}

for (_, session) in sessions.unwrap() {
for (_, session) in sessions {
if let Some(address) = session.get_address() {
Self::make_request(&address, session.pid);
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ pub fn install_plugin(path: &Path, show_progress: bool) -> Result<()> {

fn install_template(template: &Dir, path: &Path) -> Result<()> {
for file in template.files() {
fs::write(path.join(file.path()), file.contents())?;
if file.path().get_name() != ".gitkeep" {
fs::write(path.join(file.path()), file.contents())?;
}
}

for dir in template.dirs() {
Expand Down
10 changes: 2 additions & 8 deletions src/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,8 @@ pub fn get_multiple(ids: &Vec<String>) -> Result<HashMap<String, Session>> {
Ok(result)
}

pub fn get_all() -> Result<Option<HashMap<String, Session>>> {
let sessions = get_sessions()?;

if !sessions.active_sessions.is_empty() {
return Ok(Some(sessions.active_sessions));
}

Ok(None)
pub fn get_all() -> Result<HashMap<String, Session>> {
Ok(get_sessions()?.active_sessions)
}

pub fn remove(session: &Session) -> Result<()> {
Expand Down

0 comments on commit 0fa65ac

Please sign in to comment.