Skip to content

Commit

Permalink
Merge pull request #17 from hiro-o918/feature/readme
Browse files Browse the repository at this point in the history
Update README and format code style
  • Loading branch information
hiro-o918 authored Mar 4, 2022
2 parents df383bb + aa5d9d1 commit 37f005f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "awsctx"
version = "0.2.3"
version = "0.2.4"
authors = ["Hironoiri Yamamoto <[email protected]>"]
edition = "2018"
description = "Context Manager for AWS Profiles"
Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,11 @@ aws_secret_access_key = YYYYYYYYYYY
aws_session_token = YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
```

### List Profiles
`list-contexts` shows all the named profiles as the below.
```console
$ ctxm list-contexts
foo
bar
```

### Use Context
### Update the default profile by CLI
`use-context` update `~/.aws/credentials` to contain `default` profile that the values are same as specified in the option.

```console
$ ctxm use-context -p foo
$ awsctx use-context -p foo
```
e.g. the above commands updates credentials as the below.
```
Expand Down
12 changes: 8 additions & 4 deletions src/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ impl ctx::CTX for AWS {
let creds = Credentials::load_credentials(&self.credentials_path)?;
let profiles = creds.list_profiles();
Ok(profiles
.iter()
.into_iter()
.map(|p| ctx::Context {
name: p.name.clone(),
name: p.name,
active: p.default,
})
.collect())
Expand All @@ -47,14 +47,18 @@ impl ctx::CTX for AWS {
}

fn use_context_interactive(&self) -> Result<ctx::Context, ctx::CTXError> {
let mut contexts = self.list_contexts().unwrap();
let mut contexts = self.list_contexts()?;
// skim shows reverse order
contexts.reverse();
let options = SkimOptionsBuilder::default()
.height(Some("30%"))
.multi(false)
.build()
.unwrap();
.or_else(|err| {
Err(ctx::CTXError::UnexpectedError {
source: anyhow!(err),
})
})?;

let (tx_item, rx_item): (SkimItemSender, SkimItemReceiver) = unbounded();
for context in contexts {
Expand Down
1 change: 1 addition & 0 deletions src/creds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const DEFAULT_PROFILE_KEY: &str = "[default]";
pub struct Profile {
pub name: String,
pub default: bool,
#[allow(dead_code)]
items: Vec<String>,
}

Expand Down

0 comments on commit 37f005f

Please sign in to comment.