Skip to content

Commit

Permalink
chore: update meroctl (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejVukosav authored Dec 19, 2024
1 parent e2940bd commit 2599ed9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 111 deletions.
2 changes: 1 addition & 1 deletion docs/02-getting-started/01-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ A `--protocol` flag defines protocol for the node contexts.
:::

Node configuration file contains protocol defined metada. Node file is located
under username/.calimero folder.
under `~/.calimero` folder.

<Tabs
defaultValue="near"
Expand Down
2 changes: 0 additions & 2 deletions docs/05-developer-tools/01-CLI/01-merod.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ change the location by using the `--home` option.

### Examples:

Here's a table that organizes the examples you provided:

| **Command** | **Description** |
| -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| `merod --node-name node1 init` | Initialize a node with default settings. (server-port = 2428 and swarm-port = 2528`) |
Expand Down
196 changes: 88 additions & 108 deletions docs/05-developer-tools/01-CLI/02-meroctl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,165 +3,145 @@ id: meroctl
title: Meroctl
---

## Overview

The meroctl CLI provides a powerful feature called "dev mode" that allows
developers to test their applications locally before publishing them to the
network. This mode is particularly useful during the development and testing
phases of your application.

All of the communication with your node through the meroctl CLI is protected by
your nodes private key.

## Why Use Dev Mode?

Dev mode offers several advantages:

1. **Local Testing**: Test your application on your local machine without
needing to publish it to the network.
2. **Quick Iterations**: Make changes to your application and immediately test
them without going through the full publication process.
3. **Context Creation**: Automatically create a context and link it to your
local application.
4. **Hot Reload-like Functionality**: Any changes to the binary will
automatically reflect in the context, eliminating the need to "upload" the
app again after every change.

## Prerequisites

Before using dev mode, ensure you have a node running. This should be done in a
separate terminal window. For more information, see the
[Setup guide](/getting-started/setup).

To list all supported commands for the cli, run the following command:
Meroctl is a command-line tool that enables you to use node functionalities.

```bash title="Terminal"
cargo run -p meroctl -- help
meroctl [OPTIONS] --node-name <NAME> <COMMAND>
```

Supported commands:
### Commands:

- `context` Manage contexts
- `app` Manage applications
- `app` Command for managing applications
- `context` Command for managing contexts
- `identity` Command for managing applications
- `json-rpc` Executing read and write Json RPC calls
- `proxy` Command for managing proxy contract
- `call` Executing read and write RPC calls
- `help` Print this message or the help of the given subcommand(s)

Here's the basic syntax:
:::tip

All commands share the same prefix:
Run help to get more information about the available options and commands.

```bash title="Terminal"
cargo run -p meroctl -- --node-name <node_name> <command>
meroctl --help
```

### Parameters:

- `--node-name`: Specifies the name of the node.
:::

- `--path`: Specifies the absolute path to your WASM file.
### Options:

Create dev context using installed app
- `--home <PATH>` Directory for config and data
- `-n`, `--node-name <NAME>` Name of node
- `-h`, `--help` Print help
- `-output-format <FORMAT>` [default: plain-text] [possible values:
json, plain-text]
- `-V`, `--version` Print version

```bash title="Terminal"
cargo run -p meroctl -- --node-name <node_name> context create --watch <path>
```
:::tip

Output
Default location of the config and data directory is `~/.calimero`. You can
change the location by using the `--home` option.

```bash title="Terminal"
$ cargo run -p meroctl -- --node-name node1 context create --watch ./path/to/binary.wasm
Application `<appId>` installed!
Context `<contextId>` created!
Context{contextId} -> Application{appId}
(i) Watching for changes to "./path/to/binary.wasm"
```
:::

Invite other local nodes to participate in the context
:::note

```bash title="Terminal"
cargo run -p meroctl -- --node-name node2 context join --context-id contextId
```
All of the communication with your node through the meroctl CLI is protected by
your nodes private key.

Output
:::

```bash title="Terminal"
Context <contextId> sucesfully joined
```
### Examples:

Create context command will:
| **Command** | **Description** |
| ------------------------------------------------------------------------------------- | --------------------------------------- |
| `meroctl --node-name <NAME> app <COMMAND>` | Command for managing applications |
| `meroctl --node-name <NAME> context <COMMAND>` | Command for managing contexts |
| `meroctl --node-name <NAME> identity <COMMAND>` | Command for managing identities |
| `meroctl --node-name <NAME> json-rpc [OPTIONS] --as <EXECUTOR> <CONTEXT_ID> <METHOD>` | Executing read and write Json RPC calls |
| `meroctl --node-name <NAME> proxy <COMMAND>` | Command for managing proxy contract |
| `meroctl --node-name <NAME> call [OPTIONS] --as <EXECUTOR> <CONTEXT_ID> <METHOD>` | Executing read and write RPC calls |

1. Install your application locally.
2. Create a new context.
3. Link the context to your local application.
### Manage Applications

### Automatic Updates
```bash title="Terminal"
meroctl --node-name <NAME> app <COMMAND>
```

One of the key benefits of dev mode is its ability to automatically reflect
changes in your application. When you modify and recompile your WASM binary,
these changes are immediately available in the context without requiring you to
"upload" or reinstall the application. This feature provides a seamless
development experience, similar to "hot reload" functionality in other
development environments.
Commands:

### Other useful commands
- `get` Fetch application details
- `install` Install an application
- `list` List installed applications

1. List existing contexts
### Manage Contexts

```bash title="Terminal"
$ cargo run -p meroctl -- --node-name node1 context ls
meroctl --node-name <NAME> context <COMMAND>
```

2. Create a context for a published application:
Commands:

```bash title="Terminal"
$ cargo run -p meroctl -- --node-name node1 context create --application-id <appId>
```
- `list` List all contexts
- `create` Create a new context
- `join` Join an application context
- `invite` Create invitation to a context for a invitee
- `get` Fetch details about the context
- `delete` Delete an context
- `watch` Watch events from a context
- `update` Update app in context

Output
### Manage Identities

```bash title="Terminal"
Context `contextId` created!
Context{contextId} -> Application{appId}
meroctl --node-name <NAME> identity <COMMAND>
```

3. Update applications in a context
Commands:

```bash title="Terminal"
# Update with a published application ID
cargo run -p meroctl -- --node-name node1 context update --context-id <context-id> -a <application-id> --as <identity>
- `generate` Generate public/private key pair used for context identity

# Update with a local application file (one-time)
cargo run -p meroctl -- --node-name node1 context update --context-id <context-id> --path ./path/to/file --as <identity>
### Executing read and write Json RPC calls

# Update with a local application file (watch mode / reccuring updates)
cargo run -p meroctl -- --node-name node1 context update --context-id <context-id> --path ./path/to/file --watch --as <identity>
```bash title="Terminal"
meroctl --node-name <NAME> json-rpc [OPTIONS] --as <EXECUTOR> <CONTEXT_ID> <METHOD>
```

The update command allows you to:
Arguments:

- `<CONTEXT_ID>` ContextId of the context
- `<METHOD>` Method to fetch details

- Update a context to use a different published application
- Install and update to a local application file
- Watch a local application file for changes and automatically update the contex
Options:

### From development to Publication
- `--args <ARGS>` JSON arguments to pass to the method
- `--as <EXECUTOR>` Public key of the executor
- `--id <ID>` Id of the JsonRpc execute call [default: dontcare]

When you're ready to move from local development to publishing your application:
### Command for managing proxy contract

1. Test your application thoroughly using dev mode.
```bash title="Terminal"
meroctl --node-name <NAME> proxy <COMMAND>
```

2. When satisfied with your application's performance, follow the steps in the
Publish App guide to publish your application to the network.
Commands:

3. After publication, you can create contexts for your published application
using the --application-id flag instead of dev mode.
- `get` Fetch details about the proxy contract

Install the local app on node for debugging
### Executing read and write RPC calls

```bash title="Terminal"
cargo run -p meroctl -- --node-name <node_name> app install –-path <path>
meroctl --node-name <NAME> call [OPTIONS] --as <EXECUTOR> <CONTEXT_ID> <METHOD>
```

Output
Arguments:

```bash title="Terminal"
Application installed successfully. Application ID: <appId>
```
- `<CONTEXT_ID>` ContextId of the context
- `<METHOD>` Method to fetch details

Options:

- `--args <ARGS>` JSON arguments to pass to the method
- `--as <EXECUTOR>` Public key of the executor
- `--id <ID>` Id of the JsonRpc execute call [default: dontcare]

0 comments on commit 2599ed9

Please sign in to comment.