Skip to content

Commit

Permalink
Initial attempt of implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jihchi committed Oct 19, 2021
1 parent fee39d9 commit b3275fb
Show file tree
Hide file tree
Showing 28 changed files with 5,728 additions and 39 deletions.
201 changes: 187 additions & 14 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ repository = "https://github.com/jihchi/kq.git"
license-file = "LICENSE"
keywords = ["kdl", "query", "transform", "config", "document"]

[dev-dependencies]
assert_cmd = "2.0.2"
predicates = "2.0.3"
indoc = "1.0.3"

[dependencies]
kdl = "1.1.0"
kdl = "3.0.0"
nom = "7.0.0"
getopts = "0.2"
36 changes: 24 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@
[![Crates.io - download](https://img.shields.io/crates/d/kq)](https://crates.io/crates/kq)
[![docs.rs](https://img.shields.io/docsrs/kq)](https://docs.rs/kq)

> 🚧 work in progress
A jq-like cli tool that can [query](https://github.com/kdl-org/kdl/blob/1.0.0/QUERY-SPEC.md) and transform [KDL](https://kdl.dev/) document right in the command line.

A jq-like cli tool that can [query](https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md) and transform [KDL](https://kdl.dev/) document right in the command line.
> `||` and [Map Operator](https://github.com/kdl-org/kdl/blob/1.0.0/QUERY-SPEC.md#map-operator) are not supported yet.
## Installation

### Cargo

```sh
cargo install kq
```

## Usage

> Modified from https://github.com/kdl-org/kdl/blob/1.0.0/QUERY-SPEC.md#examples
Given following content:

```console
$ cat example.kdl
Expand All @@ -20,34 +34,32 @@ package {
miette "2.0.0" dev=true
}
}
```

```console
$ cat example.kdl | kq "package name"
name "foo"
```

```console
$ cat example.kdl | kq "dependencies"
dependencies platform="windows" {
winapi "1.0.0" path="./crates/my-winapi-fork"
}
dependencies {
miette "2.0.0" dev=true
}
```

```console
$ cat example.kdl | kq "dependencies[platform]"
dependencies platform="windows" {
winapi "1.0.0" path="./crates/my-winapi-fork"
}
```

```console
$ cat example.kdl | kq "dependencies > []"
winapi "1.0.0" path="./crates/my-winapi-fork"
miette "2.0.0" dev=true

```

## Installation

### Cargo

```sh
cargo install kq
```

7 changes: 2 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ impl Args {
program,
})
}
}

impl Args {
pub fn help(&self) -> bool {
self.matches.opt_present("h")
}
Expand All @@ -37,9 +35,8 @@ impl Args {
self.matches.opt_present("v")
}

pub fn get_free(&self) -> Option<String> {
let some = !self.matches.free.is_empty();
some.then(|| self.matches.free[0].clone())
pub fn get_query(&self) -> Option<&String> {
self.matches.free.get(0)
}

pub fn print_help(&self) {
Expand Down
Loading

0 comments on commit b3275fb

Please sign in to comment.