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

Add ark-cli crate #13

Merged
merged 26 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c4c165b
Initial commit
kirillt Jan 10, 2022
bd9a0c5
Tag storages backup implemented
kirillt Jan 19, 2022
127f8ae
Collisions detection subcommand
kirillt Jan 23, 2022
97a12a9
Moved index construction into the lib
kirillt Jan 24, 2022
ffe96f7
Updating dependency to arklib
kirillt Feb 9, 2022
47d1d54
Folder monitoring
kirillt Feb 10, 2022
739fec6
Refreshing interval for folder monitoring
kirillt Feb 11, 2022
a35c4a0
Adding PDF rendering command (#2)
j4w3ny Jun 14, 2022
7f4220e
Repo link and typo fixed
kirillt Jun 14, 2022
206532b
Add subcommand for working with Link-to-Web resources
kirillt Aug 19, 2022
749da4b
#15: Persisted index and metadata storage (#8)
kirillt Nov 23, 2022
2b26a64
Updating backup tool
kirillt Jan 17, 2023
812cd04
Add README.md
mberry Sep 20, 2023
3a140aa
Bump arklib version to `0d25eb0` (#14)
kirillt Jan 3, 2024
df1fc37
Added storage commands
alvinosh Jan 5, 2024
4ee759f
Adjust to new commit in arklib
kirillt Jan 13, 2024
600e6e4
Links handling and file command
alvinosh Jan 20, 2024
e2ecaae
Storage abstraction
alvinosh Jan 27, 2024
b3112c1
Add `list` command
alvinosh Feb 13, 2024
5503217
Sorting by scores, filtering by tags. Add `Usage.md`
alvinosh Feb 19, 2024
d19dc2e
Minor changes. Update `Usage.md`
kirillt Feb 29, 2024
413dff2
#19: Print URLs (#27)
alvinosh Mar 8, 2024
3203802
docs: fix parameters in Usage of list subcommand (#26)
tareknaser Apr 3, 2024
284b372
refactor: add `ark-cli` crate
tareknaser Apr 6, 2024
1b4f5ff
refactor: add `ark-cli` to cargo workspace
tareknaser Apr 7, 2024
231a6ce
fix(ark-cli): use `ark-rust_hot_fix` branch of `arklib`
tareknaser Apr 7, 2024
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"ark-cli",
"data-error",
"data-json",
"data-link",
Expand All @@ -14,6 +15,7 @@ members = [
]

default-members = [
"ark-cli",
"data-error",
"data-json",
"data-link",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The purpose of the library is to manage _resource index_ of folders with various

| Package | Description |
| --------------- | ---------------------------------------- |
| `ark-cli` | The CLI tool to interact with ark crates |
| `data-resource` | Resource hashing and ID construction |
| `fs-index` | Resource Index construction and updating |
| `fs-storage` | Filesystem storage for resources |
Expand Down
22 changes: 22 additions & 0 deletions ark-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "ark-cli"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "ark-cli"

[dependencies]
tokio = { version = "1.35.1", features = ["full"] }
arklib = { git = "https://github.com/ARK-Builders/arklib", branch = "ark-rust_hot_fix" }
clap = { version = "3.0.10", features = ["derive"] }
env_logger = "0.9.0"
fs_extra = "1.2.0"
walkdir = "2.3.2"
home = "0.5.3"
url = { version = "2.2.2", features = ["serde"] }
serde_json = "1.0.82"
serde = { version = "1.0.138", features = ["derive"] }
chrono = "0.4.34"
anyhow = "1.0.80"
thiserror = "1.0.57"
111 changes: 111 additions & 0 deletions ark-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Ark-CLI

### Installation

To compile you will need openssl libraries and headers:

```shell
# macOS (Homebrew)
$ brew install openssl@3

# macOS (MacPorts)
$ sudo port install openssl

# macOS (pkgsrc)
$ sudo pkgin install openssl

# Arch Linux
$ sudo pacman -S pkg-config openssl

# Debian and Ubuntu
$ sudo apt-get install pkg-config libssl-dev

# Fedora
$ sudo dnf install pkg-config perl-FindBin openssl-devel

# Alpine Linux
$ apk add pkgconfig openssl-dev
```

### Usage

```shell
ark-cli <SUBCOMMAND>

OPTIONS:
-h, --help Print help information

SUBCOMMANDS:
backup
collisions
help Print this message or the help of the given subcommand(s)
link
monitor
render

```

#### Backup
```shell
USAGE:
ark-cli backup [ROOTS_CFG]

ARGS:
<ROOTS_CFG>

OPTIONS:
-h, --help Print help information
```

#### Collisions
```shell
USAGE:
ark-cli collisions [ROOT_DIR]

ARGS:
<ROOT_DIR>

OPTIONS:
-h, --help Print help information
```

#### Link
```shell
USAGE:
ark-cli link <SUBCOMMAND>

OPTIONS:
-h, --help Print help information

SUBCOMMANDS:
create
help Print this message or the help of the given subcommand(s)
load
```

#### Monitor
```shell
USAGE:
ark-cli monitor [ARGS]

ARGS:
<ROOT_DIR>
<INTERVAL>

OPTIONS:
-h, --help Print help information
```

#### Render
```shell
USAGE:
ark-cli render [ARGS]

ARGS:
<PATH>
<QUALITY>

OPTIONS:
-h, --help Print help information

```
192 changes: 192 additions & 0 deletions ark-cli/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# Usage

## Get started

Create an empty dir:
```
mkdir /tmp/test
cd /tmp/test
```

Let's fill it with something. One of the simplest ways to create resources it is to save a link to web page using `ark-cli link` command:
```
$ ark-cli link create . http://google.com goo
$ ark-cli link create . http://duckduckgo.com duck
```

We can use `ark-cli list` to see just created resources:
```
22-207093268
18-1909444406
```

These are just ids, derived from the URLs themselves.

Now, the dir structure should resemble this:
```
/tmp/test
└───.ark
├───cache
│ ├───metadata
│ └───previews
└───user
├───properties
├───scores
└───tags
```

### Label your data

You can attach various metadata to your data, e.g. tags:
```
$ ark-cli file append . tags 22-207093268 search,engine
```

The same way we can append scores:
```
$ ark-cli file append . scores 22-207093268 15
```

Generic metadata is possible using JSON-based properties:
```
$ ark-cli file append . properties 22-207093268 favorites:false,ai:true --format=json
```

### Navigate your data

The simplest command to observe your resources is `list`:
```
$ ark-cli list

18-1909444406
22-207093268
```

You can also target this command to other folders:
```
$ ark-cli list ~/Pictures/

58922-3276384608
62591-2492670715
723145-720506115
125308-3041567246
```

But it's a bit boring and doesn't really tell anything, right? Various flags should be used to gain more knowledge about your collections of resources:
* `--entry=id|path|both|link` to show the path,the id or both of a resource
* `--modified` to show or not the last modified timestamp of a resource
* `--tags=true` to show or not the tags for every resource
* `--scores=true` to show or not the scores for every resource
* `--sort=asc|desc` to sort resources by asc or dsc order of scores
* `--filter=query` to filter resources by their tags

For instance, you can list files with their paths and attached tags:
```
$ ark-cli list -pt

30-4257856154 search
18-1909444406 hello
22-207093268 search,engine
38-103010298 NO_TAGS
```

You Can list the links of the files

```
$ark-cli list -l

https://google.com
https://news.ycombinator.com
https://youtube.com
https://github.com

```

Or, sort by score:
```
$ ark-cli list -s --sort=asc

30-4257856154 NO_SCORE
18-1909444406 2
38-103010298 10
22-207093268 15
```

Finally, you can filter resources using their tags:
```
$ /tmp/ark-cli list -t --filter=search

30-4257856154 search
22-207093268 search,engine
```

## :zap: Low-level utilities :zap:

There are commands which could be useful with time, when you grasp the basic concepts. Some of these commands also can be useful for debugging [ArkLib](https://github.com/ARK-Builders/ark-rust).

### Retrieve the metadata

You can read these properties:
```
$ ark-cli file read . properties 22-207093268
{"ai":"true","desc":null,"favorites":"false","title":"duck"}
```

As well as scores or tags:
```
$ ark-cli file read . scores 22-207093268
15
$ ark-cli file read . tags 22-207093268
search,engine
```

### Inspect storages

It's also possible to list resources having some metadata in a particular storage:
```
$ ark-cli storage list . properties
22-207093268
18-1909444406

$ ark-cli storage list . tags
22-207093268

$ ark-cli storage list . scores
22-207093268
```

Note that, in this example, resource with id `18-1909444406` is listed only in `properties` storage since it lacks any metadata in `tags` and `scores` storages. The `ark-cli storage list` command only lists entries of a particular storage, not all resources.

### Inspect versions

For delving into history of storage mutations, we made `--versions` flag:
```
$ ark-cli storage list . properties --versions=true
version name machine path
2 22-207093268 0592a937-a5d1-4843-8f03-ae0d6a9e77b5 ./.ark/user/properties/22-207093268/22-207093268_0592a937-a5d1-4843-8f03-ae0d6a9e77b5.2
1 18-1909444406 0592a937-a5d1-4843-8f03-ae0d6a9e77b5 ./.ark/user/properties/18-1909444406/18-1909444406_0592a937-a5d1-4843-8f03-ae0d6a9e77b5.1
```

Each storage mutation made by `ark-cli file append` or `ark-cli file insert` commands increases the number in `version` column. Versions help to prevent dirty-writes caused by using same storages by separate apps, or devices.

The `properties` storage is _folder-based_, but same command can be used with _file-based_ storages like `tags`:
```
$ ark-cli storage list . tags --versions=true
Loading app id at /home/kirill/.ark...
id value
22-207093268 search,engine

$ ark-cli file append . tags 22-207093268 wow
$ ark-cli storage list . tags --versions=true
id value
22-207093268 search,engine
22-207093268 wow

$ ark-cli file append . tags 22-207093268 one_more_time
$ ark-cli storage list . tags --versions=true
id value
22-207093268 search,engine
22-207093268 wow
22-207093268 one_more_time
```
1 change: 1 addition & 0 deletions ark-cli/ark-shelf/16-720383087
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://bing.com/
1 change: 1 addition & 0 deletions ark-cli/ark-shelf/18-1909444406
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://google.com/
Loading
Loading