Developer Guidelines & Code Conventions
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The ipatool project is a Go-based command-line interface (CLI) designed to interact with the Apple App Store for searching and downloading iOS application packages (.ipa files). These guidelines serve to maintain code quality, ensure consistent CLI behavior, and provide a roadmap for developers and automated agents contributing to the repository.
The project emphasizes idiomatic Go, minimal dependency introduction, and strict adherence to standard formatting to ensure a cohesive development experience. Sources: AGENTS.md:1-10, README.md:1-15
General Development Workflow
Developers are expected to follow a structured workflow to maintain the stability of the tool. Key requirements include:
- Consistency: New command implementations in the
cmd/directory must maintain a consistent tone and behavior with existing commands. - Minimalism: Changes should be focused and minimal to reduce the risk of regressions.
- Backward Compatibility: CLI flags and output formats must be preserved unless a change is explicitly requested.
- Validation: Before finalizing changes, developers must run formatting and the standard test suite.
Sources: AGENTS.md:11-20
Local Verification Commands
The following commands are used to validate the project state:
go generate ./...
go test ./...
go build ./...
Sources: AGENTS.md:21-27
Architecture and Design Patterns
Dependency Injection
The project utilizes a Dependencies struct to manage shared resources across commands, including loggers, OS abstractions, and the App Store client. This promotes testability by allowing components to be mocked during unit tests.
The initWithCommand function initializes these dependencies by reading CLI flags such as --verbose and --format. Sources: cmd/common.go:20-30, cmd/common.go:88-105
Command Structure
Commands are implemented using the spf13/cobra library. The rootCmd serves as the entry point, configuring global flags and persistent pre-run logic.
| Flag | Type | Description | Default |
|---|---|---|---|
--format | string | Output format: 'text' or 'json' | text |
--verbose | bool | Enables verbose logging | false |
--non-interactive | bool | Runs in a non-interactive session | false |
--keychain-passphrase | string | Passphrase for unlocking the keychain | "" |
Sources: cmd/root.go:21-45, README.md:52-64
Coding Conventions
Language and Formatting
- Idiomatic Go: All code must follow standard Go idioms and
gofmtformatting. - Error Handling: Errors should be wrapped with context using
fmt.Errorf("...: %w", err)to maintain a clear trace. - Logging: The project uses
zerologfor structured logging. JSON output is synchronized toos.Stdout.
Sources: AGENTS.md:28-35, cmd/common.go:42-55, pkg/appstore/appstore_download.go:41-50
HTTP Client and Networking
Networking is handled by a custom HTTP client wrapper that manages:
- Cookie Persistence: Uses a persistent cookie jar stored in the user's home directory.
- Response Handling: Supports JSON and XML (Apple Plist) unmarshaling with automatic normalization of Apple-specific XML envelopes.
- User Agent: Sets a default User-Agent via a custom
RoundTripper.
CLI Implementation Details
File Path Resolution
The tool resolves destination paths for downloads based on provided input or the current working directory. It handles .tmp file creation during the download process to ensure data integrity before applying patches. Sources: pkg/appstore/appstore_download.go:81-100, pkg/appstore/appstore_download.go:200-220
Patching and Metadata
Downloaded .ipa files undergo a patching process where metadata is injected into iTunesMetadata.plist. This includes the user's Apple ID email and display name.
Conclusion
Adhering to these guidelines ensures that ipatool remains a reliable and maintainable tool for the community. By following the established dependency injection patterns, networking conventions, and CLI structures, developers can contribute features that are consistent with the existing ecosystem while maintaining high standards for code quality and user experience.