Command: search
Relevant source files
The following files were used as context for generating this wiki page:
The search command is a core feature of IPATool that allows users to query the Apple App Store for iOS applications. It serves as the primary discovery mechanism for identifying application metadata, such as Bundle Identifiers and App IDs, which are required for subsequent actions like purchasing or downloading .ipa files.
The command interfaces with the public iTunes Search API to retrieve application details based on a user-provided search term. It supports filtering by country (derived from the user's StoreFront) and limiting the number of results returned to the user.
Sources: README.md:68-81, pkg/appstore/appstore_search.go:27-38
Architecture and Data Flow
The search command follows a layered architecture where the CLI layer captures user input, the application layer processes business logic (like country code resolution), and the infrastructure layer handles the actual HTTP communication with Apple's servers.
Search Execution Flow
The following diagram illustrates the end-to-end flow when a user executes a search query:
The logic starts by converting the account's StoreFront into a country code, which is then used to parameterize the GET request to the iTunes API.
Sources: pkg/appstore/appstore_search.go:27-44, pkg/http/client.go:88-101
Key Components and Data Structures
Data Models
The search functionality relies on specific structures to define inputs and parse API responses.
| Structure | Description | Fields |
|---|---|---|
SearchInput | Parameters for the search operation. | Account, Term (string), Limit (int64) |
SearchOutput | The final result returned to the CLI. | Count (int), Results ([]App) |
App | Represents an iOS application. | ID, BundleID, Name, Version, Price |
searchResult | Internal structure for unmarshaling JSON. | resultCount (int), results ([]App) |
Sources: pkg/appstore/appstore_search.go:12-25, pkg/appstore/appstore_search.go:47-50, pkg/appstore/app_test.go:44-52
API Interaction
The tool constructs a specific URL to interact with the iTunes API. The request is a GET method, and the response format is expected to be JSON.
The search URL includes specific parameters such as entity=software,iPadSoftware and media=software to ensure only relevant iOS applications are returned.
Sources: pkg/appstore/appstore_search.go:52-68, pkg/http/client.go:125-142
Implementation Details
Request Construction
The searchURL function assembles the query parameters. It uses url.Values to ensure proper encoding of the search term and other variables.
Sources: pkg/appstore/appstore_search.go:60-68
func (t *appstore) searchURL(term, countryCode string, limit int64) string {
params := url.Values{}
params.Add("entity", "software,iPadSoftware")
params.Add("limit", strconv.Itoa(int(limit)))
params.Add("media", "software")
params.Add("term", term)
params.Add("country", countryCode)
return fmt.Sprintf("https://%s%s?%s", iTunesAPIDomain, iTunesAPIPathSearch, params.Encode())
}
Sources: pkg/appstore/appstore_search.go:60-68
Response Handling
The system validates that the HTTP status code is 200 OK. If the request fails or returns a non-OK status, it returns an error wrapped with metadata containing the failed result.
Sources: pkg/appstore/appstore_search.go:34-41
CLI Usage and Flags
The search command is accessed via the ipatool search <term> syntax.
| Flag | Shorthand | Default | Description |
|---|---|---|---|
--limit | -l | 5 | Maximum amount of search results to retrieve. |
--format | - | text | Sets output format; can be 'text' or 'json'. |
--verbose | - | false | Enables verbose logging. |
Sources: README.md:73-81, cmd/root.go:39-44
Summary
The search command provides a robust interface for querying Apple's application catalog. By leveraging the iTunes Search API and integrating with the tool's internal account management (via StoreFront country codes), it provides the essential metadata required for the tool's subsequent download and purchase workflows.