pinoc 0.1.3

A CLI tool for setting up pinocchio program project
<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 with best practices
- ๐Ÿ“ Proper directory structure for Solana/Pinocchio development
- ๐Ÿ”จ Simple build, test, and deployment commands
- ๐Ÿงน Smart project cleaning with keypair preservation
- ๐Ÿ“ฆ Package management and search functionality
- ๐Ÿ’ป Comprehensive testing environment setup
- ๐Ÿ” Automatic keypair generation and management
- ๐Ÿ”‘ Program key management with consistency checks

## 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
```

## Usage

### Available Commands

```bash
# Initialize a new project
pinoc init <project-name>

# Build your project
pinoc build

# Run tests
pinoc test

# Deploy your program
pinoc deploy

# Clean target directory (preserves keypairs by default)
pinoc clean

# Clean target directory (removes everything including keypairs)
pinoc clean --no-preserve

# Add a package to your project
pinoc add <package-name>

# Search for Pinocchio packages
pinoc search [query]

# Manage program keys
pinoc keys list          # List all program keypairs
pinoc keys sync          # Sync program ID in lib.rs with keypair

# Get help
pinoc --help
```

### Example

Create a new Pinocchio project and get started:

```bash
# Create a new project
pinoc init my-pinocchio-app

# Navigate to your project
cd my-pinocchio-app

# Build your project
pinoc build

# Run tests
pinoc test

# Clean build artifacts (preserves keypairs)
pinoc clean

# Add a package
pinoc add some-package

# Search for packages
pinoc search database

# List program keys
pinoc keys list

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

```

## 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
โ”œโ”€โ”€ 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
```

## 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
```

## 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. **Prerequisites**

   - Rust and Cargo installed
   - Solana CLI tools installed
   - Git for version control

2. **Clone and Build**

   ```bash
   git clone https://github.com/a91y/pinoc.git
   cd pinoc
   cargo build --release
   ```

3. **Install Locally**

   ```bash
   cargo install --path .
   ```

4. **Test Your Changes**

   ```bash
   # Test the CLI
   pinoc --help

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