@countrystatecity/cli 0.1.3 → 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 +5 -1
  2. package/dist/index.js +14 -22
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -59,7 +59,11 @@ csc search countries --json
59
59
  csc search states --country IN
60
60
  csc search states -c US --filter "new"
61
61
 
62
- # 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
63
67
  csc search cities --country IN --state MH
64
68
  csc search cities -c US -s CA --json
65
69
 
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.3",
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",