Skip to content
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
41 changes: 31 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,31 @@ goe://<repo_address>:<chain_id>

## Getting Started

### Install the CLI
### 1. Install the CLI
```bash
npm install -g goe-cli
```

### 1. Wallet Command
### 2. Global Configuration
Some GoE CLI parameters can be provided either as command-line flags or via environment variables.

#### Chain ID
Most `goe repo` commands require a target chain ID. You can specify it in one of the following ways:

- **Command-line flag** (highest priority):
```bash
goe repo create my-repo --chain-id 11155111
```

- **Environment variable** (applies to all commands in the current shell):
```bash
export GOE_CHAIN_ID=11155111
goe repo create my-repo
```

If both are provided, the command-line flag overrides the environment variable.

### 3. Wallet Command

Manage wallets that act as your on-chain identity.

Expand Down Expand Up @@ -83,37 +102,39 @@ goe wallet lock
> - **Unlock**: Enter your password to derive a key and store it in the system keychain to decrypt your private key for Git operations.
> - **Lock**: Remove the derived key from the system keychain to secure your wallet.

### 2. Repo Command
### 4. Repo Command

Create and manage on-chain repositories and permissions.

- **Create a repository**
```bash
goe repo create <repo_name> --chain-id <chain_id>
goe repo create <repo_name> [--chain-id <chain_id>]
```
> If --chain-id is not provided, GoE will use the GOE_CHAIN_ID environment variable.


- **List repositories**
```bash
goe repo list --chain-id <chain_id>
goe repo list [--chain-id <chain_id>]
```

- **List branches**
```bash
goe repo branches <repo_address> --chain-id <chain_id>
goe repo branches <repo_address> [--chain-id <chain_id>]
```

- **Set default branch**
```bash
goe repo default-branch <repo_address> <branch_name> --chain-id <chain_id>
goe repo default-branch <repo_address> <branch_name> [--chain-id <chain_id>]
```

- **Grant / Revoke push access**
```bash
goe repo grant-push <repo_address> <user_address> --chain-id <chain_id>
goe repo revoke-push <repo_address> <user_address> --chain-id <chain_id>
goe repo grant-push <repo_address> <user_address> [--chain-id <chain_id>]
goe repo revoke-push <repo_address> <user_address> [--chain-id <chain_id>]
```

### 3. Example Workflow
### 5. Example Workflow

#### 1). Create or unlock your wallet
```bash
Expand Down
37 changes: 22 additions & 15 deletions src/cli/repo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import { logger } from "../utils/log.js";
// 🌐 Common chainId option
const chainIdOption = new Option(
"-c, --chain-id <number>",
"Specify the chain ID (e.g., 1=Mainnet, 5=Goerli, 11155111=Sepolia)"
"Specify the chain ID (e.g., 1=Mainnet, 11155111=Sepolia)"
).argParser((val) => parseInt(val, 10));

const repoCmd = new Command('repo')
.description('Manage decentralized repositories');


function resolveChainId(cmd: any): number | null {
const chainId = cmd.chainId ?? (process.env.GOE_CHAIN_ID ? parseInt(process.env.GOE_CHAIN_ID, 10) : undefined);
if (!Number.isInteger(chainId)) return null;
return chainId;
}

// =============== 🧱 Factory Commands =================

// Create repository
Expand All @@ -20,8 +27,8 @@ repoCmd
.addOption(chainIdOption)
.description("Create a new repository (requires --chain-id)")
.action(async (name, cmd) => {
const chainId = cmd.chainId;
if (!chainId) return logger.error("You must specify --chain-id.");
const chainId = resolveChainId(cmd);
if (chainId === null) return logger.error("Chain ID not specified. Use --chain-id or set GOE_CHAIN_ID environment variable.");

try {
logger.info(`Creating repository "${name}" on chain ${chainId}...`);
Expand All @@ -41,8 +48,8 @@ repoCmd
.option("-s, --start <number>", "Start index", (val) => parseInt(val, 10), 0)
.option("-l, --limit <number>", "Items per page", (val) => parseInt(val, 10), 20)
.action(async (cmd) => {
const chainId = cmd.chainId;
if (!chainId) return logger.error("You must specify --chain-id.");
const chainId = resolveChainId(cmd);
if (chainId === null) return logger.error("Chain ID not specified. Use --chain-id or set GOE_CHAIN_ID environment variable.");

try {
const repos = await Factory.getUserReposPaginated(chainId, cmd.start, cmd.limit);
Expand All @@ -65,8 +72,8 @@ repoCmd
.addOption(chainIdOption)
.description("Set the default branch of a repository (requires --chain-id)")
.action(async (repo, branch, cmd) => {
const chainId = cmd.chainId;
if (!chainId) return logger.error("You must specify --chain-id.");
const chainId = resolveChainId(cmd);
if (chainId === null) return logger.error("Chain ID not specified. Use --chain-id or set GOE_CHAIN_ID environment variable.");

try {
logger.info(`Setting default branch for ${repo} to "${branch}"...`);
Expand All @@ -83,8 +90,8 @@ repoCmd
.addOption(chainIdOption)
.description("Grant push permission to an address (requires --chain-id)")
.action(async (repo, address, cmd) => {
const chainId = cmd.chainId;
if (!chainId) return logger.error("You must specify --chain-id.");
const chainId = resolveChainId(cmd);
if (chainId === null) return logger.error("Chain ID not specified. Use --chain-id or set GOE_CHAIN_ID environment variable.");

try {
logger.info(`Granting push permission to ${address} on ${repo}...`);
Expand All @@ -101,8 +108,8 @@ repoCmd
.addOption(chainIdOption)
.description("Revoke push permission from an address (requires --chain-id)")
.action(async (repo, address, cmd) => {
const chainId = cmd.chainId;
if (!chainId) return logger.error("You must specify --chain-id.");
const chainId = resolveChainId(cmd);
if (chainId === null) return logger.error("Chain ID not specified. Use --chain-id or set GOE_CHAIN_ID environment variable.");

try {
logger.info(`Revoking push permission from ${address}...`);
Expand All @@ -119,8 +126,8 @@ repoCmd
.addOption(chainIdOption)
.description("Grant maintainer permission to an address (requires --chain-id)")
.action(async (repo, address, cmd) => {
const chainId = cmd.chainId;
if (!chainId) return logger.error("You must specify --chain-id.");
const chainId = resolveChainId(cmd);
if (chainId === null) return logger.error("Chain ID not specified. Use --chain-id or set GOE_CHAIN_ID environment variable.");

try {
logger.info(`Granting maintainer role to ${address} on ${repo}...`);
Expand All @@ -136,8 +143,8 @@ repoCmd
.addOption(chainIdOption)
.description("List all branches in a repository")
.action(async (repo, cmd) => {
const chainId = cmd.chainId;
if (!chainId) return logger.error("You must specify --chain-id.");
const chainId = resolveChainId(cmd);
if (chainId === null) return logger.error("Chain ID not specified. Use --chain-id or set GOE_CHAIN_ID environment variable.");

try {
logger.info(`Fetching branches for ${repo}...`);
Expand Down