Giter Club home page Giter Club logo

swarm-cli's Introduction

Swarm-CLI

Node.js tests standard-readme compliant js-standard-style

Stay up to date with changes by joining the official Discord and by keeping an eye on the releases tab.

Table of Contents

Demo

Purchasing a Postage Stamp

Swarm CLI Stamp Buy Command

Uploading a File

Swarm CLI Upload Command

Creating an Identity

Swarm CLI Identity Create Command

Uploading to a Feed

Swarm CLI Feed Upload Command

Description

Manage your Bee node and interact with the Swarm network via the CLI

The goal of this project is to handle most of the Swarm operations through CLI at some point in the future.

For the currently supported operations, see the Commands section.

Installation

From npm

To install globally (requires npm root --global to be writable):

npm install --global @ethersphere/swarm-cli

To install locally:

cd [some directory for nodejs files]
npm install @ethersphere/swarm-cli
./node_modules/.bin/swarm-cli --help

From source

See the Development section.

Usage

The general usage is to provide a command, optionally a subcommand, then arguments and options.

swarm-cli command [subcommand] <arguments> [options]

Running a command with the --help option prints out the usage of a command.

Commands

Running swarm-cli without arguments prints the available commands:

Swarm CLI 1.5.0 - Manage your Bee node and interact with the Swarm network via the CLI

█ Usage:

swarm-cli COMMAND [OPTIONS]

█ Available Groups:

pinning    Pin, unpin and check pinned chunks
identity   Import, export and manage keypairs, identities
feed       Upload, update and view feeds
cheque     Deposit, withdraw and manage cheques
stamp      Buy, list and show postage stamps
pss        Send, receive, or subscribe to PSS messages
manifest   Operate on manifests

Run 'swarm-cli GROUP --help' to see available commands in a group

█ Available Commands:

upload      Upload file to Swarm
download    Download arbitrary Swarm hash
status      Check API availability and Bee compatibility
addresses   Display the addresses of the Bee node

Run 'swarm-cli COMMAND --help' for more information on a command

Example usage

Let's say we want to upload our website to Swarm and update a feed to point to the newest version. For updating a feed we would need to sign it with an Ethereum key, so first we need to create one with the identity create command:

swarm-cli identity create

This command will ask for a password. After that a new identity is created (named main). Now we can use this identity to sign updates. It's also possible to import and export Ethereum JSON V3 format identities that works with other apps (e.g. wallets).

Another requirement for uploading to the Swarm network is a valid postage batch, also called a postage stamp or simply a stamp. Stamps need to be purchased with BZZ tokens. We can use the stamp buy command to take care of this step. The --amount and --depth options alter the capacity of the postage stamp. For example, running stamp buy --amount 1 --depth 20 will get back with a Stamp ID after a while. We will be using that with the --stamp option in commands which upload files, or write feeds.

For uploading to a feed we can use the feed upload command. It expects the path of the folder (or file) we want to upload and as options it expects identity to be provided along with the password that belongs to it, as well as the earlier mentioned stamp.

swarm-cli feed upload path-to-be-uploaded --identity my-identity --password my-secret-password --stamp stamp-id

In this example we are uploading the content of the dist folder. If the uploading was successful the last printed line will contain a Feed Manifest URL. This URL can be opened in the browser. If the uploaded folder contains an index.html file then it will be automatically displayed when visiting the URL.

This URL will stay the same when we upload an updated version of the website. Because of this we can also put this URL into a reverse proxy configuration or use the reference (the hex string after the /bzz/) in an ENS record. There is more information about that in the Bee documentation. The uploaded content can be found on the link in the line starting with URL. This will change every time the content is modified.

Usability Features

Uploading Files, Folders, Websites, and Arbitrary Data from stdin

Files

Use swarm-cli to upload a single file:

swarm-cli upload README.md

The command above will print a /bzz URL that may be opened in the browser. If the browser is able to handle the file format then the file is displayed, otherwise it will be offered to be downloaded.

Folders and Websites

swarm-cli also supports uploading folders with the same upload command:

swarm-cli upload build/

This also yields a /bzz URL. If there is an index.html present in the root of the folder, --index-document will be automatically applied by swarm-cli. This option sets which file the browser should open for an empty path. You may also freely set --index-document during upload to change this.

Standard Input

You can pipe data from other commands to swarm-cli using the --stdin option.

curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp [...]

Unlike other upload methods, this results in a /bytes URL, which cannot be displayed by browsers normally. You can still share your hash and others can download it. However, with the --name option, you can give your arbitrary data a file name, and swarm-cli will attempt to determine the suitable content type for your data. Given it is successful, swarm-cli will print a /bzz URL instead of the /bytes URL, which is good to be displayed in browsers. Example:

curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp [...] --name random.jpg

There is also a --content-type option if you want to adjust it manually:

curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp [...] --name random --content-type image/jpeg

Please note that stdin is reserved for the data you are uploading, so interactive features are disabled during this time. Because of that, --stamp must be passed beforehand. You may create an alias for grabbing the ID of the least used postage stamp:

alias st='swarm-cli stamp list --least-used --limit 1 --hide-usage --quiet'

Leveraging the alias above, you can use a shortcut for uploading from stdin:

curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp $(st)

Custom HTTP Headers

Similarly to curl, you may use the --header or -H option to specify as many additional headers as you want, which will be sent with all requests:

swarm-cli upload README.md -H "Authorization: [...]" -H "X-Custom-Header: Your Value"

Autocomplete

swarm-cli has support for autocomplete in bash, zsh and fish. This turns on <tab><tab> suggestions which can complete commands, paths and options for you.

To enable it, you need to install it once via two options:

  • Running swarm-cli --generate-completion and following the instructions there
  • Running swarm-cli --install-completion which automatically appends the completion script to your configuration file
Shell Completion System Configuration Path
bash compdef & compadd OR complete & COMPREPLY $HOME/.bashrc & $HOME/.bash_profile
zsh compdef & compadd OR complete & COMPREPLY $HOME/.zshrc
fish complete $HOME/.config/fish/config.fish

Warning! If you start a subshell (e.g. running bash from zsh), your SHELL env variable would still be the old value! The generation and completion script cannot detect your shell accurately in that case, so please set SHELL manually. It is generally advised to run --generate-completion first to ensure the shell and the paths are properly detected.

Example:

$ SHELL=zsh
$ swarm-cli --generate-completion
Your shell is: zsh
Found configuration file path: /Users/Swarm/.zshrc

Append the completion script below to your configuration file to enable autocomplete.
You need to source your configuration, or restart your shell, to load the changes.

<script>

Numerical Separator and Units

As most of the units are specified in wei and PLUR - the smallest denominations of currencies - they are a bit difficult to write out.

To aid this, you may use underscores (_) and K, M, B and T units to make your numbers more comprehensible.

Example:

swarm-cli stamp buy --amount 10M --depth 17 --gas-price 10_000_000_000_000

You may combine the two: 100_000T.

Stamp Picker

Unless you are running in --quiet mode, some options are not hard-required.

Look for hints in the --help sections. Take the upload command for example:

█ Required Options:

   --stamp   ID of the postage stamp to use  [required when quiet][string]

That means, you don't have to provide the postage stamp ID beforehand. Simply running swarm-cli upload <path> will prompt you with an interactive stamp picker:

? Please select a stamp for this action.

  Stamp ID                                                         Utilization
 (Use arrow keys)
❯ b9d5bb548c2c209cb99cbb27b0bef59b8f0cd3558363e307f45177b5a64ad0c8 (1)

Identity Picker

Similarly to Stamp Picker, when an identity is not provided, an interactive picker will be prompted.

Take the command feed upload for example. Albeit it takes quite a lot of options, you can run it with typing as little as feed upload <path>.

swarm-cli will take you through some prompts to interactively specify all required options, such as identity, password of the identity, and the mandatory stamp.

Passing identities is also tolerant to errors, so if you provide one which does not exist, the output will tell you and you can correct it:

The provided identity does not exist. Please select one that exists.
? Please select an identity for this action (Use arrow keys)
❯ main

Human Readable Topics

You may need to pass topics on multiple occasions - for example, when uploading to feeds.

Topics are 32-byte long identifiers, so you need 64 characters to write them out in hexadecimal string format.

You can do that with the --topic or -t option, or alternatively take a shortcut and use a human readable string which will be hashed by swarm-cli for your convenience. It is available via the --topic-string or -T option.

Example:

swarm-cli feed upload [...] -T "Awesome Swarm Website"

This is also indicated in the --help section:

-t --topic         32-byte long identifier in hexadecimal format    [hex-string][default all zeroes]
-T --topic-string  Construct the topic from human readable strings                          [string]

Only one is required: [topic] or [topic-string]

Manifest address scheme

The manifest commands enable low-level operation on manifests. These always require a root manifest reference (hash) argument as the input. Some commands, however, work with subparts of the manifest. A few examples are: downloading only a folder from a manifest, listing files only under a specific path in a manifest, and adding files or folders not to the root of the manifest, but under some path.

These can be achieved by using the bzz://<hash>/<path> scheme in the <address> argument as follows:

List entries under the /command/pss prefix in manifest 1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f

swarm-cli manifest list bzz://1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f/command/pss

Download README.md from manifest 1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f

swarm-cli manifest download bzz://1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f/README.md

Note: The bzz:// protocol can be omitted.

Automating tasks with Swarm-CLI

Running swarm-cli with the flag --quiet (or -q for short) disables all interactive features, and makes commands print information in an easily parsable format. The exit code also indicates whether running the command was successful or not. These may be useful for automating tasks both in CI environments and in your terminal too.

Below you will find a few snippets to give an idea how it can be used to compose tasks.

Connectivity

Exit if not all status checks succeed:

swarm-cli status -q || exit 1

Check Bee API connection, compatibility does not matter:

swarm-cli status -q | head -n 1 | grep "^OK"

Postage Stamps

Grab the first postage stamp:

swarm-cli stamp list --limit 1 --quiet --hide-usage

Grab the least used postage stamp:

swarm-cli stamp list --limit 1 --quiet --hide-usage --least-used

List all postage stamps with zero utilization:

swarm-cli stamp list --max-usage 0 --quiet --hide-usage

Sort postage stamps based on utilization (least utilized comes first):

swarm-cli stamp list --least-used --quiet

Uploading

Upload a file with the least utilized postage stamp (that has at most 50% usage):

STAMP=$(swarm-cli stamp list --max-usage 50 --least-used --limit 1 --quiet --hide-usage)
swarm-cli upload -q README.md --stamp $STAMP

Config

The configuration file is placed in a hidden folder named swarm-cli.

In case of Unix-based systems this config path will be: $HOME/.swarm-cli

On Windows systems: $HOME\AppData\swarm-cli

The configuration file is saved with 600 file permission.

On first run, this configuration will be generated with default values, that you are able to change on your demand under the before mentioned path.

Assignment priority

It is possible to set value of particular parameters in different ways.

The assignment priority of how option gets its value in question is the following:

  1. passed CLI option value (with e.g. --option-example-1)
  2. env variable for that option in form of either OPTION_EXAMPLE_1 or SWARM_CLI_OPTION_EXAMPLE_1 (if it is available)
  3. CLI configuration value of that option (if it is available)
  4. option's default fallback value (or it is required to define by #1)

System environment

With specific system environment variables you can alter the behaviour of the CLI

  • BEE_API_URL - API URL of Bee client
  • BEE_DEBUG_API_URL - Debug API URL of Bee client
  • SWARM_CLI_CONFIG_FOLDER - full path to a configuration folder
  • SWARM_CLI_CONFIG_FILE - configuration file name, defaults to config.json

Development

After the project has been cloned, the dependencies must be installed. Run the following in the project folder:

 $ npm install

Then you need to compile the TypeScript code:

 $ npm run build

To make the local swarm-cli files in the dist/ directory available as a global package:

 $ npm link

If all went well you should be able to run swarm-cli.

If npm link fails, or you don't want to install anything, then you can use node dist/src/index.js to run swarm-cli from the checked out directory.

Contribute

There are some ways you can make this module better:

  • Consult our open issues and take on one of them
  • Help our tests reach 100% coverage!

Maintainers

See what "Maintainer" means here.

License

BSD-3-Clause

swarm-cli's People

Contributors

agazso avatar attila-lendvai avatar auhau avatar bee-worker avatar cafe137 avatar chawyehsu avatar dependabot[bot] avatar luissanchez0305 avatar noahmaizels avatar nugaon avatar tomicvladan avatar vandot avatar vojtechsimetka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swarm-cli's Issues

Naming: change directory to folder

On all mainstream desktop UIs directories are called folders. It would be good to adopt this naming convention all around in our displayed texts.

Some cheque commands inherit --minimum option, but is unused

Example:

█ Current Command:

cheque withdraw   Withdraw tokens from the chequebook to the overlay address        [alias: wd]

█ Arguments:

amount   Amount of tokens to withdraw                                         [required bigint]

█ Optional Options:

-m --minimum   Filter based on minimum balance                             [bigint, default: 0]

Default verbosity level

By default there is a lot of information printed on the console. It would be better to change the default verbosity level to 1 to keep it a bit down. Then if someone needs more information (for example when debugging) they can always set the verbosity level higher.

Docker command

There is a need for having a functionality to easily setup Bee node(s).
On every Bee realease, a Docker version is also available, so we could use that to pull any arbitrary version of Bee without any extra installed large dependency, and run that with the appropriate options.
Also we could use it for other Swarm JS project tests like for bee-js, where a bash script helps to solve this problem currently.
The docker setup should be able to use templates as well, which would load from configuration (which also should be placed in other file, not in config.json, as it only utilized in case of docker subcommands). One of the default template could be the former mentioned setup that the bee-js' script using, other is connecting a single node to the main Swarm network with full configuration.

Progress bar on upload to Bee client

We have already a progress bar on upload, but only for the data to be synced on the network.
Would be nice to have a progress bar before that to track the progress of sending the file to the Bee-client.

swarm-cli tries to sync even if Bee is running in standalone mode

this doesn't make sense! 🤔

Waiting for file chunks to be synced on Swarm network...
 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 99% | ETA: INFs | 2014/202074fee8cc9dbac82a954f907d15a454337f8713286af090166ab8a715ec07c02b
Data syncing timeout.

Improve general usage printing

Improvements

  • Whenever groups are listed, also print this info:
Run 'swarm-cli GROUP --help' to see available commands in a group
  • Whenever commands are listed, also print this info:
Run 'swarm-cli COMMAND --help' for more information on a command
  • When only swarm-cli is called, also print a headline, eg.:
swarm-cli v0.6.1 - Manage your Bee node and interact with the Swarm network via the CLI
  • When only swarm-cli is called, do not print error message

  • When groups are called without commands, do not print error message

  • When help is printed for a specific command, include an usage part, eg.:

█ Usage:

swarm-cli feed upload <path> [OPTIONS]
  • When commands are called without any options and arguments BUT they require an argument, print usage instead of the error message

Mockup

image

Data syncing timeout happens almost always

When trying to upload something (either with the upload command or with the feed upload command) I almost always get data syncing timeout timeout error. When trying the second time it always work. Because of this the CLI upload feels buggy.

We discussed this issue with @Cafe137 and the simple but crude fix could be to increase the sync timeout. A more sophisticated solution could be that while the values are changing restart the timeout from 0.

topic must be specified

it would be great if the default topic was specified so that it is not necessary to specify it in the cli argument.

i would suggest that the default is set to

--topic "0000000000000000000000000000000000000000000000000000000000000000"

which is the default topic for feed indirection in Bee

Feed update and upload commands

Feed update:

swarm-cli feed update --identity <identity> --topic <topic> --reference <reference>

Feed upload = upload + feed update

swarm-cli feed upload <path> --identity <identity> --topic <topic>

error caused by specifying bee-api-url with trailing slash

the error does not occur with the trailing slash removed, i.e. -bee-api-url http://localhost:1633

sig :: Code/swarm2/frontpage.github.io 1 » FRONT=true && swarm-cli --identity="fp-wallet" --password="..." feed upload --path "./dist" --bee-api-url http://localhost:1633/ --topic "0000000000000000000000000000000000000000000000000000000000000000"
r [Error]: write EPIPE
    at t.safeAxios (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:251087)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Object.t.upload (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:236117)
    at async g.uploadDirectory (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:1122225)
    at async g.run (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:1121413)
    at async u.runUpload (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:1099480)
    at async u.run (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:1099091)
    at async Object.handler (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:659211)

upload progress is not known

it would be good to also show the progress of the initial stage of the upload to the user.

in the event that the user has set up their own remote node (as I had), or the file is especially huge, this could cause some period of time without user feedback.

feature request: pin in retrospect

it would be useful to be able to pin chunks and their children, that are already existent in the network.

eg. swarm-cli pin eba7925a4d82c33affaf95fbf3885096487ceb27d8c9f1601f73db4f8ec7624a

print feed manifest hash without doing update

it would be useful to be able to retrieve a feed manifest hash/url without having to do an update

perhaps a ux variant or additional feature request would be to not update the feed if the current latest feed update matches the upload hash (i.e. the user has attempted to upload the same content as an updated)

Separate verbosity options

In many CLI tools I worked with there was a -q or --quiet option for minimal output and the -v or --verbose option for the verbose output. We can adopt that.

This would mean a breaking change from the current version, the mapping of the old options to the new ones are the following:
-v 0: -q or --quiet
-v 1: this is the default, there is no separate option for that
-v 2: -v or --verbose

Originally posted by @agazso in #26 (comment)

server error caused by upload of complex website

Uploading the following website (unzip the following file) using the following command fails with 500 server error.

DOCS=true && swarm-cli --identity="docs-wallet" --password="..." feed upload --path "./build" --bee-api-url https://x.duckdns.org --topic "0000000000000000000000000000000000000000000000000000000000000000"

docs-build.zip

bee version
0.5.2-4a598b6

Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file docs/index.html with reference 7692177579638825102d49b34574d44ff1c7660b5d2faea172f57559001645a6"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file test-site/assets/style.css with reference 39fd1e40767fe2b5775e4c04d5ba72e960154f2ccfeb266f53d32403ae53e4ed"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file test-site/index.html with reference da42b666eeb0f51ae3e2e6b84193d09b177ac190b03649dfacb9bfb3ba855caa"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file test-site/my_website.tar with reference 4f6246ddef3d6a500738d9da4688512c16f7396175fa3ab093de7c147ee2cb98"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file debug-api/index.html with reference 4a83f0fe0c860705e102f294367b79ab8fbf62cd0c0182fb74947ccb2bc8a067"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file index.html with reference ae2bfbc74170c2aacf35bb0df5bbb3e0cf84e5f09effd3427e65d7ee31c6a1de"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file .DS_Store with reference 6678bb7a9f960ca5706768ef4d0ff4e0ac56ce4642c019c77c817a8625d10e67"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file lunr-index.json with reference 72a4b7dd40102464317e03b391767fe650a26ba21852c75f9a39de474b290632"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file search-doc.json with reference dfd5c7f485ffc0ac8d5ce8efe3af0ce01e49bf3216bec500670adab2bb738fe1"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file 404.html with reference e11a82d1ff4cc1533b2cc2dcb67492dc6148cc138cfd3bc869f20b133d3f00c8"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=trace msg="uploaded dir file bee.jpg with reference 042d4fe94b946e2cb51196a8c136b8cc335156525bf1ad7e86356c2402291dd4"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=debug msg="dir upload: store dir err: store dir file: split file: inconsistent references"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=error msg="dir upload: store dir"
Mar 17 12:45:05 ip-172-31-43-105 bee[24699]: time="2021-03-17T12:45:05Z" level=info msg="api access" duration=0.419122041 ip=127.0.0.1 method=POST proto=HTTP/1.0 size=46 status=500 uri=/dirs user-agent=axios/0.21.1 x-real-ip=81.100.58.90

Bee Debug API URL value set

You can only pass the Bee Debug API URL by CLI option parameter, but would be nice to define it by system variable and config parameter as well (as in case of Bee API URL you can do that).

Printing a feed should not require a password

Using the feed print command now requires a password to be specified. However for printing the details of a feed there is no need for the private key (therefore password), only the address which should be available without a password.

URL of uploaded folder without `--index-document`

If I upload a folder without the --index-document flag then the resulted URL given by the command pointing to the bzz endpoint will result in error in the browser (ERR_TOO_MANY_REDIRECTS).

Maybe don't show the URL if no --index-document is displayed?

Unify group descriptions

█ Available groups:

pinning    Pinning utilities
identity   Keypair management interface
feed       Feed utilities
cheque     Cheque

Sometimes it is called utilities, sometimes interface. Cheque is blank.

Cashout command

Currently users are using a bash script to cash out.

The CLI could also provide this functionality and it can be better maintained than a shell script on the long run. Also this would solve the issue that running shell script on Windows is not trivial.

Currently the script has three subcommands:

  • cashout <peer>: cashes out the cheques from a single peer
  • cashout-all <min-amount>: cashes out all the cheques that reaches a minimum amount
  • list-uncashed: list all uncashed cheques

Binary packaging

It's possible to build a single binary executable without dependencies and it may make it easier to distribute the CLI to users who don't have Node and NPM installed.

There is a tool called pkg that I tried and it works, by default it builds intel 64-bit binaries for linux, macos and windows. The only issue is that the binaries are 81M whereas the webpack built JS file is only 3M. So I think we need further research on this topic.


  • Build x64 binaries and host them
  • Verify the binaries work properly
  • Do the same with arm64 binaries
  • Incorporate building binaries into the CI

Feed upload /bzz reference only works with directories, not single files

Steps to reproduce:

  • Upload a single file with feed upload
  • Open Feed Manifest URL (/bzz)
  • Receive { "message": "Not Found", "code": 404 }

This works with directories when --index-document is specified. When --index-document is NOT specified, error is ERR_TOO_MANY_REDIRECTS, but that is off topic.

Note: In all 3 scenarios described above, the /feeds/{owner}/{topic} endpoint returns a JSON object with a reference property.

Possible solution is to modify bee-js so that it allows passing indexDocument in uploadFile if the core bee API permits it. In that case the index document should be auto-filled by swarm-cli to be the same as the uploaded file. This raises a question though: how would feed update work, since the file name is unknown by then.

Error when using recursive (-r) option

I was trying to use the recursive option to upload a directory to Bee and I get an error (see below). Interestingly if I am not using the recursive option the upload of a directory is still successful.

~/Projects/swarm-cli (feat/identity*) % node dist/index.js upload -r ../swarm-cli/dist                                 
index.js upload <path>

- Upload file to Swarm

Positionals:
  path  Path of the file (even directory)                             [required]

Options:
      --help                Show help                                  [boolean]
      --version             Show version number                        [boolean]
      --bee-api-url         URL of the Bee-client API
                                     [string] [default: "http://localhost:1633"]
      --config-folder       Path of the configuration files that the CLI uses
                                                                        [string]
      --pin                 Persist the uploaded data on the gateway node
                                                                       [boolean]
  -r, --recursive           Upload directory            [string] [default: true]
      --tag-polling-time    Waiting time in ms between tag pollings
                                                         [string] [default: 500]
      --tag-polling-trials  After the given trials the tag polling will stop
                                                          [string] [default: 15]
      --index-document      Default retrieval file on bzz request without
                            provided filepath   [string] [default: "index.html"]
      --error-document      Default error file on bzz request without with wrong
                            filepath                                    [string]

Not enough non-option arguments: got 0, need at least 1

Required options are a bit hard to find in help

This is a usability issue: since we use are using options to provide arguments they do not show up in the help text describing the command, only at the bottom of the help saying Missing required arguments. Then you have to see all the options to find out the required ones to see how they work.

I think it would be better if the required arguments were shown in a more distinct way (for example separating them in a block by newlines) or maybe sort the list of options alphabetically so that they are easier to find.

For example this is an actual output:

% node dist/index.js feed upload
index.js feed upload

- Upload to a feed

Options:
      --help           Show help                                       [boolean]
      --version        Show version number                             [boolean]
      --bee-api-url    URL of the Bee-client API
                                     [string] [default: "http://localhost:1633"]
      --config-folder  Path of the configuration files that the CLI uses[string]
  -v, --verbosity      Print console messages in the given relevance level
  [string] [choices: "0", "1", "2", "Quiet", "Normal", "Verbose"] [default: "2"]
      --identity       Name of the identity                  [string] [required]
      --topic          Feed topic                            [string] [required]
      --password       Password for the wallet                          [string]
      --hash-topic     Hash the topic to 32 bytes                      [boolean]
      --path           Path of the file                      [string] [required]

Missing required arguments: identity, topic, path

no guards against cli argument if specified twice

i accidentally specified topic twice, and got unexpected results.

FRONT=true && swarm-cli --identity="fp-wallet" --password="..." feed upload --path "./dist" --bee-api-url http://localhost:1633 --topic "0000000000000000000000000000000000000000000000000000000000000000" --topic "0000000000000000000000000000000000000000000000000000000000000000"
TypeError: this.topic.startsWith is not a function
    at u.enforceValidHexTopic (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:1094028)
    at u.getTopic (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:1093800)
    at updateFeedAndPrint (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:1093185)
    at async u.run (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:1099114)
    at async Object.handler (/Users/sig/.nvm/versions/node/v14.6.0/lib/node_modules/@ethersphere/swarm-cli/dist/index.js:3:659211)

In case of any errors the help and a callstack is always printed

When there is an (unhandled) error during running a command, the help and an exception with the callstack is always printed. This makes it hard to find the actual error because it indicates the user that maybe the invocation was wrong.

It would be better if the help were only printed when there was an error specifying the arguments, otherwise only an (actionable) error message would be printed.

For example if you give an address to --bee-api-url that cannot be found this is the output:

% node dist/index.js feed upload dist/index.js --bee-api-url https://gateways.ethswarm.org -i main -P 1 
index.js feed upload <path>

- Upload to a feed

Positionals:
  path  Path to the file or folder                                    [required]

Options:
      --bee-api-url         URL of the Bee-client API
                                     [string] [default: "http://localhost:1633"]
      --bee-debug-api-url   URL of the Bee-client Debug API
                                     [string] [default: "http://localhost:1635"]
      --config-folder       Path of the configuration files that the CLI uses
                                                                        [string]
  -v, --verbose             Print all console messages [string] [default: false]
  -q, --quiet               Only print the results     [string] [default: false]
  -i, --identity            Name of the identity             [string] [required]
  -t, --topic               Feed topic         [string] [default: 32 zero bytes]
  -P, --password            Password for the wallet                     [string]
  -H, --hash-topic          Hash the topic to 32 bytes[boolean] [default: false]
      --pin                 Persist the uploaded data on the gateway node
                                                                       [boolean]
      --tag-polling-time    Waiting time in ms between tag pollings
                                                         [string] [default: 500]
      --tag-polling-trials  After the given trials the tag polling will stop
                                                          [string] [default: 15]
      --index-document      Default retrieval file on bzz request without
                            provided filepath                           [string]
      --error-document      Default error file on bzz request without with wrong
                            filepath                                    [string]
  -V, --version             Show version number                        [boolean]
  -h, --help                Show help                                  [boolean]

r [Error]: getaddrinfo ENOTFOUND gateways.ethswarm.org
    at t.safeAxios (/Users/attila/Projects/swarm-cli/dist/index.js:3:251742)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Object.t.createTag (/Users/attila/Projects/swarm-cli/dist/index.js:3:244154)
    at async y.run (/Users/attila/Projects/swarm-cli/dist/index.js:3:1131005)
    at async u.runUpload (/Users/attila/Projects/swarm-cli/dist/index.js:3:1108393)
    at async u.run (/Users/attila/Projects/swarm-cli/dist/index.js:3:1108221)
    at async Object.handler (/Users/attila/Projects/swarm-cli/dist/index.js:3:660658)
Exit 1

Identity: Import and Export commands

New commands:

swarm-cli identity export <[identity-name]>
  • Export prints a valid V3 wallet to console as beautified JSON.
  • Supports picking an identity from a list if no argument is provided.

swarm-cli identity import <path> [--identity-name] [--password]
  • Import takes the path of a V3 wallet, tests the given password, and places the wallet to the swarm-cli config.json as a new identity.
  • If the identity name is not provided, it will repeatedly ask user for a non-colliding identity name later in the flow.
  • It is enough to provide the path, identity name and password can be specified later in a user friendly way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.