pinoc 0.1.5

A CLI tool for setting up pinocchio program project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<div align="center">
  <img src="assets/logo.png" alt="Pinoc CLI Logo" width="20%">
  <h1>Pinoc</h1>
  <p>Setup Solana Pinocchio projects blazingly fast</p>

  [![Crates.io](https://img.shields.io/crates/v/pinoc)](https://crates.io/crates/pinoc)
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
  [![Rust](https://img.shields.io/badge/rust-1.70+-blue.svg)](https://www.rust-lang.org)

  **Authors:**

  <a class="header-badge" target="_blank" href="https://twitter.com/AyushAgr91">
    <img alt="Twitter" src="https://img.shields.io/badge/@AyushAgr91-000000?style=for-the-badge&logo=x&logoColor=white">
  </a>
  <a class="header-badge" target="_blank" href="https://twitter.com/4rjunc">
    <img alt="Twitter" src="https://img.shields.io/badge/@4rjunc-000000?style=for-the-badge&logo=x&logoColor=white">
  </a>
</div>

## About

Pinoc is a command-line tool designed to make it easy to set up and manage [Pinocchio](https://github.com/anza-xyz/pinocchio) projects on Solana. It automates common development tasks including project initialization, building, testing, and deployment with simple commands.

## Features

- ๐Ÿš€ **Fast Project Scaffolding** - Create new projects with best practices in seconds
- ๐Ÿ“ **Proper Directory Structure** - Solana/Pinocchio development structure out of the box
- ๐Ÿ”จ **Simple Commands** - Build, test, and deploy with intuitive commands
- ๐Ÿงน **Smart Project Cleaning** - Clean build artifacts while preserving keypairs
- ๐Ÿ“ฆ **Package Management** - Add dependencies and search for Pinocchio packages
- ๐Ÿ’ป **Comprehensive Testing** - Built-in testing environment with mollusk-svm
- ๐Ÿ” **Automatic Keypair Management** - Generate and manage program keypairs
- ๐Ÿ”‘ **Program Key Sync** - Keep your program IDs consistent with smart checking
- โš™๏ธ **Configuration Management** - Use Pinoc.toml for deployment settings

## Installation

### From crates.io (Recommended)

```bash
cargo install pinoc
```

### From GitHub

```bash
cargo install --git https://github.com/a91y/pinoc --force
```

### From Source

1. **Clone the repository**
   ```bash
   git clone https://github.com/a91y/pinoc.git
   cd pinoc
   ```

2. **Build the tool**
   ```bash
   cargo build --release
   ```

3. **Install globally**
   ```bash
   cargo install --path .
   ```

## Quick Start

```bash
# Install pinoc
cargo install pinoc

# Create a new project
pinoc init my_awesome_app

# Navigate to your project
cd my_awesome_app

# Build and test
pinoc build
pinoc test

# Deploy to Solana
pinoc deploy

# Create a new project without git initialization
pinoc init my_awesome_app --no-git
# This will skip git repository initialization.
```

## Usage

### Available Commands

| Command | Description |
|---------|-------------|
| `pinoc init <project-name> [--no-git] [--no-boilerplate]` | Initialize a new Pinocchio project (skip git init with --no-git, minimal structure with --no-boilerplate) |
| `pinoc build` | Build your Solana program |
| `pinoc test` | Run project tests |
| `pinoc deploy [--cluster] [--wallet]` | Deploy your program to Solana (uses Pinoc.toml config, optional overrides) |
| `pinoc clean [--no-preserve]` | Clean target directory (preserves keypairs by default) |
| `pinoc add <package-name>` | Add a package to your project |
| `pinoc search [query]` | Search for Pinocchio packages |
| `pinoc keys list` | List all program keypairs |
| `pinoc keys sync` | Sync program ID in lib.rs with keypair |
| `pinoc --help` | Get help and see all available commands |
| `pinoc help` | Display custom help banner with all commands |

### Complete Workflow Example

```bash
# Create a new project
pinoc init my_pinocchio_app

# Create a new project without git initialization
pinoc init my_pinocchio_app --no-git

# Create a minimal project without tests and boilerplate
pinoc init my_minimal_project --no-boilerplate

# Navigate to your project
cd my_pinocchio_app

# Build your project
pinoc build

# Run tests
pinoc test

# List program keys
pinoc keys list

# Sync program keys (checks consistency first)
pinoc keys sync

# Clean build artifacts (preserves keypairs)
pinoc clean

# Add a package
pinoc add some_package

# Search for packages
pinoc search database

# Get help
pinoc help

# Deploy your program
pinoc deploy

# Deploy with custom cluster and wallet
pinoc deploy --cluster devnet --wallet ./custom-keypair.json
```

## Project Structure

When you initialize a project with `pinoc init`, it creates the following structure:

```
my_project/
โ”œโ”€โ”€ Cargo.toml              # Project configuration with Pinocchio dependencies
โ”œโ”€โ”€ README.md               # Project documentation
โ”œโ”€โ”€ .gitignore              # Git ignore file
โ”œโ”€โ”€ Pinoc.toml              # Deployment configuration
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ lib.rs              # Library crate using no_std
โ”‚   โ”œโ”€โ”€ entrypoint.rs       # Program entrypoint
โ”‚   โ”œโ”€โ”€ errors.rs           # Error definitions
โ”‚   โ”œโ”€โ”€ instructions/       # Program instructions
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ initialize.rs   # Initialize instruction
โ”‚   โ””โ”€โ”€ states/             # Account state definitions
โ”‚       โ”œโ”€โ”€ mod.rs
โ”‚       โ”œโ”€โ”€ state.rs        # State structure
โ”‚       โ””โ”€โ”€ utils.rs        # State management utilities
โ”œโ”€โ”€ tests/                  # Test files
โ”‚   โ””โ”€โ”€ tests.rs            # Unit tests using mollusk-svm
โ””โ”€โ”€ target/
    โ””โ”€โ”€ deploy/
        โ””โ”€โ”€ my_project-keypair.json  # Generated program keypair

```

### Minimal Project

When you initialize a project with `pinoc init --no-boilerplate`, it creates a minimal structure:

```
my_minimal_project/
โ”œโ”€โ”€ Cargo.toml              # Minimal configuration with only pinocchio dependency
โ”œโ”€โ”€ README.md               # Basic documentation
โ”œโ”€โ”€ .gitignore              # Git ignore file
โ”œโ”€โ”€ Pinoc.toml              # Deployment configuration
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ lib.rs              # Minimal program with just program ID and basic structure
โ””โ”€โ”€ target/
    โ””โ”€โ”€ deploy/
        โ””โ”€โ”€ my_minimal_project-keypair.json  # Generated program keypair
```

**Minimal Project Features:**
- **No Tests**: No test directory or test dependencies
- **No Boilerplate**: No instructions, states, or utility files
- **Essential Only**: Just the core files needed to build and deploy
- **Fast Setup**: Perfect for quick prototypes or learning

## Key Features in Detail

### ๐Ÿงน Smart Project Cleaning

The `pinoc clean` command intelligently manages your build artifacts:

```bash
# Clean target directory while preserving keypairs (default)
pinoc clean

# Clean everything including keypairs
pinoc clean --no-preserve
```

**Why preserve keypairs?** Your program keypair is essential for deployment. The default behavior ensures you don't accidentally lose your deployment credentials.

### ๐Ÿ“ฆ Package Management

Easily add dependencies and discover new packages:

```bash
# Add a package to your project
pinoc add package-name

# Search for Pinocchio-related packages
pinoc search database
pinoc search oracle
```

### ๐Ÿ” Automatic Keypair Management

- **Generation**: Keypairs are automatically created during project initialization
- **Preservation**: Clean commands preserve keypairs by default
- **Security**: Keypairs are stored securely in `target/deploy/`

### ๐Ÿ”‘ Program Key Management

Manage your program keys with consistency checks:

```bash
# List all program keypairs
pinoc keys list

# Sync program ID in lib.rs with keypair
pinoc keys sync
```

**Key Sync Features:**

- **Consistency Check**: Verifies if the program ID in `declare_id!` matches the keypair's public key
- **Smart Updates**: Only updates the file if there's a mismatch
- **Clear Feedback**: Shows current state and any changes made
- **No Unnecessary Writes**: Prevents file updates when keys are already consistent

**Example Output:**

```bash
# When keys are already consistent
โœ… Program key is already consistent!
๐Ÿ”‘ Program ID: 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
๐Ÿ“ No update needed in src/lib.rs

# When keys need syncing
๐Ÿ”„ Program key mismatch detected:
   Current in lib.rs: 11111111111111111111111111111111
   Actual keypair:    9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
โœ… Successfully synced program key!
๐Ÿ”‘ Program ID: 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
๐Ÿ“ Updated src/lib.rs with new program ID
```

### โš™๏ธ Configuration Management

Pinoc uses a `Pinoc.toml` configuration file to manage deployment settings. This file is automatically created when you initialize a new project.

**Pinoc.toml Structure:**

```toml
[provider]
cluster = "localhost"
wallet = "~/.config/solana/id.json"
```

**Configuration Options:**

- **`cluster`**: The Solana cluster URL to deploy to (e.g., "localhost", "devnet", "mainnet-beta")
- **`wallet`**: Path to your Solana wallet keypair file (supports `~` for home directory expansion)

**Deployment Process:**

When you run `pinoc deploy`, the tool will:

1. Read the `Pinoc.toml` configuration file
2. Display the cluster and wallet being used
3. Deploy your program using the specified settings

**Command-Line Overrides:**

You can override the configuration from `Pinoc.toml` using command-line arguments:

```bash
# Override cluster only
pinoc deploy --cluster devnet

# Override wallet only  
pinoc deploy --wallet ./custom-keypair.json

# Override both cluster and wallet
pinoc deploy --cluster mainnet-beta --wallet ~/.config/solana/mainnet-keypair.json
```

**Example Deployment Output:**

```bash
$ pinoc deploy
Deploying program
๐Ÿ“‹ Using configuration:
   Cluster: devnet
   Wallet: ~/.config/solana/id.json
Program deployed successfully!
```

**Customizing Configuration:**

You can edit the `Pinoc.toml` file to change deployment settings, or use command-line arguments for one-time overrides:

```toml
# For mainnet deployment
[provider]
cluster = "mainnet-beta"
wallet = "~/.config/solana/mainnet-keypair.json"

# For local development
[provider]
cluster = "localhost"
wallet = "~/.config/solana/id.json"
```

**Command-Line Override Examples:**

```bash
# Use different cluster for this deployment
pinoc deploy --cluster devnet

# Use different wallet for this deployment
pinoc deploy --wallet ./test-keypair.json

# Override both settings
pinoc deploy --cluster mainnet-beta --wallet ~/.config/solana/production-keypair.json
```

## Prerequisites

Before using Pinoc, make sure you have the following installed:

- **Rust and Cargo** - [Install Rust]https://rustup.rs/
- **Solana CLI Tools** - [Install Solana CLI]https://docs.solana.com/cli/install-solana-cli-tools
- **Git** - For version control

## Contributing

Contributions are welcome! Here's how you can contribute:

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Run tests to ensure everything works
5. Commit your changes (`git commit -m 'Add some amazing feature'`)
6. Push to the branch (`git push origin feature/amazing-feature`)
7. Open a Pull Request

### Development Setup

1. **Clone and Build**
   ```bash
   git clone https://github.com/a91y/pinoc.git
   cd pinoc
   cargo build --release
   ```

2. **Install Locally**
   ```bash
   cargo install --path .
   ```

3. **Test Your Changes**
   ```bash
   # Test the CLI
   pinoc --help

   # Create a test project
   pinoc init test-project
   cd test-project
   pinoc build
   ```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support

- ๐Ÿ“– **Documentation**: This README and the [Pinocchio documentation]https://github.com/anza-xyz/pinocchio
- ๐Ÿ› **Issues**: Report bugs and request features on [GitHub Issues]https://github.com/a91y/pinoc/issues