@countrystatecity/cli 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +29 -3
  2. package/dist/index.js +14 -22
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # @countrystatecity/cli
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@countrystatecity/cli)](https://www.npmjs.com/package/@countrystatecity/cli)
4
+ [![CI](https://github.com/dr5hn/countrystatecity-npm/workflows/Pipeline/badge.svg)](https://github.com/dr5hn/countrystatecity-npm/actions/workflows/ci.yml)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@countrystatecity/cli?label=cli)](https://www.npmjs.com/package/@countrystatecity/cli)
6
+ [![npm downloads](https://img.shields.io/npm/dw/@countrystatecity/cli?label=cli)](https://www.npmjs.com/package/@countrystatecity/cli)
7
+
3
8
  Official CLI for the [Country State City API](https://countrystatecity.in) — search, explore, and generate code from geographic data.
4
9
 
5
10
  ```bash
@@ -19,6 +24,16 @@ csc search countries
19
24
  csc get country IN
20
25
  ```
21
26
 
27
+ ## Global Flags
28
+
29
+ These flags work on every command:
30
+
31
+ | Flag | Short | Description |
32
+ |------|-------|-------------|
33
+ | `--json` | | Output raw JSON instead of formatted tables |
34
+ | `--quiet` | `-q` | Suppress all decorative output (spinners, tips) |
35
+ | `--no-footer` | | Hide the API usage footer after each command |
36
+
22
37
  ## Commands
23
38
 
24
39
  ### Authentication
@@ -27,7 +42,9 @@ csc get country IN
27
42
  csc auth login # Interactive login with API key
28
43
  csc auth login --key <KEY> # Login with key directly
29
44
  csc auth status # Check current auth status
45
+ csc auth status --json # Returns { authenticated, key, tier, daily, monthly }
30
46
  csc auth logout # Remove stored API key
47
+ csc auth logout --json # Returns { success: true }
31
48
  ```
32
49
 
33
50
  ### Search
@@ -42,7 +59,11 @@ csc search countries --json
42
59
  csc search states --country IN
43
60
  csc search states -c US --filter "new"
44
61
 
45
- # List cities for a state
62
+ # List all cities for a country
63
+ csc search cities --country IN
64
+ csc search cities --country IN --json
65
+
66
+ # List cities for a specific state
46
67
  csc search cities --country IN --state MH
47
68
  csc search cities -c US -s CA --json
48
69
 
@@ -56,9 +77,12 @@ csc search india
56
77
  # Detailed country info (timezones, coordinates, currency, etc.)
57
78
  csc get country IN
58
79
  csc get country US --json
80
+ csc get country # Interactive — prompts to pick a country (TTY only)
59
81
 
60
82
  # Detailed state info
61
83
  csc get state IN MH
84
+ csc get state IN MH --json
85
+ csc get state # Interactive — prompts for country then state (TTY only)
62
86
  ```
63
87
 
64
88
  ### Usage & Billing
@@ -66,9 +90,11 @@ csc get state IN MH
66
90
  ```bash
67
91
  # View API usage with progress bars
68
92
  csc usage
93
+ csc usage --json # Returns { plan, price, daily, monthly }
69
94
 
70
95
  # View plans and open pricing page
71
96
  csc upgrade
97
+ csc upgrade --json # Returns { plans, currentPlan }
72
98
  ```
73
99
 
74
100
  ### Code Generation
@@ -88,9 +114,9 @@ csc generate seed --entity countries --format prisma
88
114
  csc generate seed -e states -f prisma --country IN
89
115
  csc generate seed -e cities -f prisma -c IN -s MH
90
116
 
91
- # Options
117
+ # Options (apply to both dropdown and seed)
92
118
  --output <dir> # Output directory (default: current directory)
93
- --no-typescript # Generate .jsx instead of .tsx
119
+ --no-typescript # Generate .jsx instead of .tsx (dropdown only)
94
120
  ```
95
121
 
96
122
  #### Example: Generated Country Dropdown
package/dist/index.js CHANGED
@@ -490,7 +490,7 @@ function registerSearchCommands(program2) {
490
490
  }
491
491
  printUsageFooter(usage, flags);
492
492
  });
493
- search3.command("cities").description("List cities for a state").option("-c, --country <iso2>", "Country ISO2 code").option("-s, --state <iso2>", "State ISO2 code").option("--filter <text>", "Filter by name").action(
493
+ search3.command("cities").description("List cities for a country or state").option("-c, --country <iso2>", "Country ISO2 code").option("-s, --state <iso2>", "State ISO2 code (omit to get all cities in the country)").option("--filter <text>", "Filter by name").action(
494
494
  async (options, cmd) => {
495
495
  const globalOpts = cmd.optsWithGlobals();
496
496
  const flags = {
@@ -511,26 +511,18 @@ function registerSearchCommands(program2) {
511
511
  return;
512
512
  }
513
513
  }
514
- let stateCode = options.state?.toUpperCase();
515
- if (!stateCode) {
516
- if (isTTY()) {
517
- const stateSpinner = await createSpinner(`Loading states for ${countryCode}...`, flags);
518
- const { data: allStates } = await get(`/countries/${countryCode}/states`);
519
- stateSpinner.stop();
520
- stateCode = await promptState(allStates);
521
- } else {
522
- process.stderr.write(chalk5.red("State code required. Use --state MH\n"));
523
- process.exit(1);
524
- return;
525
- }
514
+ const stateCode = options.state?.toUpperCase();
515
+ let endpoint;
516
+ let spinnerText;
517
+ if (stateCode) {
518
+ endpoint = `/countries/${countryCode}/states/${stateCode}/cities`;
519
+ spinnerText = `Fetching cities for ${countryCode}/${stateCode}...`;
520
+ } else {
521
+ endpoint = `/countries/${countryCode}/cities`;
522
+ spinnerText = `Fetching all cities for ${countryCode}...`;
526
523
  }
527
- const spinner = await createSpinner(
528
- `Fetching cities for ${countryCode}/${stateCode}...`,
529
- flags
530
- );
531
- const { data, usage } = await get(
532
- `/countries/${countryCode}/states/${stateCode}/cities`
533
- );
524
+ const spinner = await createSpinner(spinnerText, flags);
525
+ const { data, usage } = await get(endpoint);
534
526
  spinner.stop();
535
527
  let cities = data;
536
528
  if (options.filter) {
@@ -1328,7 +1320,7 @@ async function promptCountry2(countries) {
1328
1320
  }
1329
1321
  });
1330
1322
  }
1331
- async function promptState2(states) {
1323
+ async function promptState3(states) {
1332
1324
  return search2({
1333
1325
  message: "Select a state",
1334
1326
  source: (input) => {
@@ -1396,7 +1388,7 @@ async function runExploreSession(flags) {
1396
1388
  stderr(`No states found for ${countryIso}.`);
1397
1389
  return latestUsage;
1398
1390
  }
1399
- const stateIso = await promptState2(states);
1391
+ const stateIso = await promptState3(states);
1400
1392
  const selectedState = states.find((s) => s.iso2 === stateIso);
1401
1393
  const stateName = selectedState?.name ?? stateIso;
1402
1394
  let running = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@countrystatecity/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Official CLI for the Country State City API - search, explore, and generate code from geographic data",
5
5
  "files": [
6
6
  "dist",