Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve insomnia import #165

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [Unreleased] - ReleaseDate

### Changed

- Show `WARN`/`ERROR` log output for CLI commands
- Improvements to Insomnia import ([#12](https://github.com/LucasPickering/slumber/issues/12))
- Rename `import-experimental` command to `import`
- It's official now! It's still going to get continuted improvement though

## [0.18.0] - 2024-04-18

### Breaking
Expand Down
17 changes: 17 additions & 0 deletions 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
Expand Up @@ -46,7 +46,7 @@ strum = {version = "^0.26.0", default-features = false, features = ["derive"]}
thiserror = "^1.0.48"
tokio = {version = "^1.32.0", default-features = false, features = ["fs", "macros", "process", "rt", "rt-multi-thread"]}
tracing = "^0.1.37"
tracing-subscriber = {version = "^0.3.17", default-features = false, features = ["env-filter", "fmt", "registry"]}
tracing-subscriber = {version = "^0.3.17", default-features = false, features = ["ansi", "env-filter", "fmt", "registry"]}
url = {version = "^2.5.0", features = ["serde"]}
uuid = {version = "^1.4.1", default-features = false, features = ["serde", "v4"]}

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ Slumber is a TUI (terminal user interface) HTTP client. Define, execute, and sha
- You own your data: all configuration and data is stored locally and can be checked into version control
- It will never be [enshittified](https://en.wikipedia.org/wiki/Enshittification)

## Features

- Usable as a TUI or CLI
- [Import from external formats (e.g. Insomnia)](https://slumber.lucaspickering.me/book/user_guide/import.html)
- [Build requests dynamically from other requests, files, and shell commands](https://slumber.lucaspickering.me/book/user_guide/templates.html)
- [Browse response data using JSONPath selectors](https://slumber.lucaspickering.me/book/user_guide/filter_query.html)
- Switch between different environments easily using [profiles](https://slumber.lucaspickering.me/book/api/request_collection/profile.html)
- And more!

## Examples

Slumber is based around **collections**. A collection is a group of request **recipes**, which are templates for the requests you want to run. A simple collection could be:
Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Chaining Requests](./user_guide/chaining_requests.md)
- [Collection Reuse & Inheritance](./user_guide/inheritance.md)
- [Data Filtering & Querying](./user_guide/filter_query.md)
- [Importing External Collections](./user_guide/import.md)

# API Reference

Expand Down
12 changes: 6 additions & 6 deletions docs/src/api/request_collection/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ slumber collections list

A request collection supports the following top-level fields:

| Field | Type | Description | Default |
| ---------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `profiles` | [`mapping[string, Profile]`](./profile.md) | Static template values | `{}` |
| `requests` | [`mapping[string, RequestRecipe]`](./request_recipe.md) | Requests Slumber can send | `{}` |
| `chains` | [`mapping[string, Chain]`](./chain.md) | Complex template values | `{}` |
| `.ignore` | Any | Extra data to be ignored by Slumber (useful with [YAML anchors](https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/)) | |
| Field | Type | Description | Default |
| ---------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | ------- |
| `profiles` | [`mapping[string, Profile]`](./profile.md) | Static template values | `{}` |
| `requests` | [`mapping[string, RequestRecipe]`](./request_recipe.md) | Requests Slumber can send | `{}` |
| `chains` | [`mapping[string, Chain]`](./chain.md) | Complex template values | `{}` |
| `.ignore` | Any | Extra data to be ignored by Slumber (useful with [YAML anchors](https://yaml.org/spec/1.2.2/#anchors-and-aliases)) | |

## Examples

Expand Down
2 changes: 1 addition & 1 deletion docs/src/user_guide/filter_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ chains:
recipe: login
selector: $.token

# Use YAML anchors for de-duplication
# Use YAML anchors and merge syntax for de-duplication
.ignore:
base: &base
headers:
Expand Down
34 changes: 34 additions & 0 deletions docs/src/user_guide/import.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Importing External Collections

Slumber can generate a collection file from external formats, making it easy to switch over. Currently the only supported format is Insomnia.

## Disclaimer

Importers are **approximate**. They'll give the you skeleton of a collection file, but don't expect 100% equivalency. They save a lot of tedious work for you, but you'll generally still need to do some manual work on the collection file to get what you want.

## Examples

The general format is:

```sh
slumber import <format> <input> [output]
```

For example, to import from an Insomnia collection `insomnia.json`:

```sh
slumber import insomnia insomnia.json slumber.yml
```

## Formats

Supported formats:

- Insomnia

Requested formats:

- [OpenAPI](https://github.com/LucasPickering/slumber/issues/106)
- [JetBrains HTTP](https://github.com/LucasPickering/slumber/issues/122)

If you'd like another format supported, please [open an issue](https://github.com/LucasPickering/slumber/issues/new).
1 change: 0 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use std::process::ExitCode;
pub enum CliCommand {
Request(RequestCommand),
Generate(GenerateCommand),
#[clap(name = "import-experimental")]
Import(ImportCommand),
Collections(CollectionsCommand),
Show(ShowCommand),
Expand Down
16 changes: 12 additions & 4 deletions src/cli/import.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{cli::Subcommand, collection::Collection, GlobalArgs};
use anyhow::Context;
use async_trait::async_trait;
use clap::Parser;
use clap::{Parser, ValueEnum};
use std::{
fs::File,
io::{self, Write},
Expand All @@ -12,18 +12,26 @@ use std::{
/// Generate a Slumber request collection from an external format
#[derive(Clone, Debug, Parser)]
pub struct ImportCommand {
/// Input format
format: Format,
/// Collection to import
input_file: PathBuf,
/// Destination for the new slumber collection file. Omit to print to
/// stdout.
/// Destination for the new slumber collection file [default: stdout]
output_file: Option<PathBuf>,
}

#[derive(Copy, Clone, Debug, ValueEnum)]
enum Format {
Insomnia,
}

#[async_trait]
impl Subcommand for ImportCommand {
async fn execute(self, _global: GlobalArgs) -> anyhow::Result<ExitCode> {
// Load the input
let collection = Collection::from_insomnia(&self.input_file)?;
let collection = match self.format {
Format::Insomnia => Collection::from_insomnia(&self.input_file)?,
};

// Write the output
let mut writer: Box<dyn Write> = match self.output_file {
Expand Down
Loading
Loading