Skip to content

Commit

Permalink
added print feature & removed nix
Browse files Browse the repository at this point in the history
  • Loading branch information
sreedevk committed Jan 4, 2025
1 parent 2cf361c commit 581858d
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 3,450 deletions.
559 changes: 393 additions & 166 deletions Cargo.lock

Large diffs are not rendered by default.

3,079 changes: 0 additions & 3,079 deletions Cargo.nix

This file was deleted.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blaze-ssh"
version = "0.0.6"
version = "0.0.7"
edition = "2021"
authors = ["Sreedev Kodichath <[email protected]>"]
description = "A Configurable CLI tool that helps you ssh into aws ec2 instances without leaving the terminal"
Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,11 @@ This tool attempts to solve the problem by keeping the dependencies at a minimum
A few conveniences of aws-ssh are missing, but will be added soon along with some additional features like aws-ecs support.

## Installation
Currently, there are two ways to install blaze-ssh

### Using Cargo

```bash
$ cargo install blaze-ssh --git https://github.com/sreedevk/blaze-ssh
```

### Using Nix Profile

```bash
$ nix profile install 'github:sreedevk/blaze-ssh?ref=main'
```

After installation, make sure to create a config file at `~/.config/blaze/config.toml`. See [Configuration](#configuration) for more details.
You may use the `configure` command to generate a default config file.

Expand All @@ -43,6 +34,7 @@ Usage: blssh [OPTIONS] <COMMAND>
Commands:
connect connect to an ec2 instances
list list filtered ec2 instances
print Print SSH Command
configure generate default config (~/.config/blssh/config.toml)
help Print this message or the help of the given subcommand(s)

Expand All @@ -52,8 +44,6 @@ Options:
-h, --help Print help

# Connection Opts
connect to an ec2 instances

Usage: blssh connect [OPTIONS] [SEARCH]

Arguments:
Expand Down Expand Up @@ -116,6 +106,11 @@ $ blssh --config ~/custom-config.toml connect production-1
# Disable use of cached instance information (stored in /tmp/blaze_ssh_cache.json)
$ blssh --no-cache connect production-1
```
### Printing The SSH Command to Connect to an Instance

```bash
$ blssh print production-1
```

# Known Issues
1. When navigating using j/k on the connect ui, the list scroll doesn't work. [PR #2]
Expand Down
127 changes: 0 additions & 127 deletions flake.lock

This file was deleted.

41 changes: 0 additions & 41 deletions flake.nix

This file was deleted.

73 changes: 48 additions & 25 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,67 @@ mod ui;

use std::process::Command;

use anyhow::Result;
use anyhow::{anyhow, Result};
use clap::Parser;
use instance_details::InstanceSet;
use opts::Opts;
use tablegen::TableGenerator;
use ui::Ui;

fn gencmd(
opts: opts::ConnectOptions,
cli: Opts,
instance_set: InstanceSet,
cmd: &mut Command,
) -> Result<&mut Command> {
let filtered_instance_set = instance_set.filter(&opts.search)?;
let instance = match filtered_instance_set.is_non_selectable() {
true => filtered_instance_set.instances.first().unwrap().clone(),
false => {
let mut ui = Ui::new(
filtered_instance_set,
config::Config::read_raw(cli.clone().config)?,
)?;

ui.run()?
}
};

if instance.is_empty() {
eprintln!("No instance found");
return Err(anyhow!("No Instance Found"));
}

/* run ssh */
let config = config::Config::load(cli.clone().config)?;
let command_generator = cmdgen::CommandGenerator::new(&opts, config, instance)?;
command_generator.generate(cmd)
}

#[tokio::main]
async fn main() -> Result<()> {
let cli = Opts::parse();
let instance_set = InstanceSet::fetch(&cli).await?;
match cli.clone().operation {
let operation = cli.operation.clone();
match operation.clone() {
opts::Operations::Connect(opts) => {
let filtered_instance_set = instance_set.filter(&opts.search)?;
let instance = match filtered_instance_set.is_non_selectable() {
true => filtered_instance_set.instances.first().unwrap().clone(),
false => {
let mut ui = Ui::new(
filtered_instance_set,
config::Config::read_raw(cli.clone().config)?,
)?;

ui.run()?
}
};

if instance.is_empty() {
eprintln!("No instance found");
return Ok(());
let mut command = Command::new("sh");
if let Ok(cmd) = gencmd(opts, cli, instance_set, &mut command) {
cmd.status()?;
}

/* run ssh */
let config = config::Config::load(cli.clone().config)?;
let command_generator = cmdgen::CommandGenerator::new(&opts, config, instance)?;
}
opts::Operations::Print(opts) => {
let mut command = Command::new("sh");
let ssh_command = command_generator.generate(&mut command)?;

ssh_command.status()?;
if let Ok(cmd) = gencmd(opts, cli, instance_set, &mut command) {
println!(
"{}",
cmd.get_args()
.last()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
);
}
}
opts::Operations::List(opts) => {
let filtered_instance_set = instance_set.filter(&opts.search)?;
Expand Down
3 changes: 3 additions & 0 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub enum Operations {
/// list filtered ec2 instances
#[clap(name = "list", alias = "l")]
List(ListOptions),
/// Print SSH Command
#[clap(name = "print", alias = "p")]
Print(ConnectOptions),
/// generate default config (~/.config/blssh/config.toml)
#[clap(name = "configure", alias = "cfg")]
Configure,
Expand Down

0 comments on commit 581858d

Please sign in to comment.