@countrystatecity/cli 0.1.3 → 0.1.5

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 +8 -1
  2. package/dist/index.js +26 -37
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -55,11 +55,18 @@ csc search countries
55
55
  csc search countries --filter "united"
56
56
  csc search countries --json
57
57
 
58
+ # List all states globally
59
+ csc search states
60
+
58
61
  # List states for a country
59
62
  csc search states --country IN
60
63
  csc search states -c US --filter "new"
61
64
 
62
- # List cities for a state
65
+ # List all cities for a country
66
+ csc search cities --country IN
67
+ csc search cities --country IN --json
68
+
69
+ # List cities for a specific state
63
70
  csc search cities --country IN --state MH
64
71
  csc search cities -c US -s CA --json
65
72
 
package/dist/index.js CHANGED
@@ -449,28 +449,25 @@ function registerSearchCommands(program2) {
449
449
  }
450
450
  printUsageFooter(usage, flags);
451
451
  });
452
- search3.command("states").description("List states for a country").option("-c, --country <iso2>", "Country ISO2 code").option("--filter <text>", "Filter by name").action(async (options, cmd) => {
452
+ search3.command("states").description("List states for a country, or all states globally").option("-c, --country <iso2>", "Country ISO2 code (omit to get all states globally)").option("--filter <text>", "Filter by name").action(async (options, cmd) => {
453
453
  const globalOpts = cmd.optsWithGlobals();
454
454
  const flags = {
455
455
  json: globalOpts.json ?? false,
456
456
  quiet: globalOpts.quiet ?? false,
457
457
  noFooter: globalOpts.footer === false
458
458
  };
459
- let code = options.country?.toUpperCase();
460
- if (!code) {
461
- if (isTTY()) {
462
- const countrySpinner = await createSpinner("Loading countries...", flags);
463
- const { data: allCountries } = await get("/countries");
464
- countrySpinner.stop();
465
- code = await promptCountry(allCountries);
466
- } else {
467
- process.stderr.write(chalk5.red("Country code required. Use --country IN\n"));
468
- process.exit(1);
469
- return;
470
- }
459
+ const code = options.country?.toUpperCase();
460
+ let endpoint;
461
+ let spinnerText;
462
+ if (code) {
463
+ endpoint = `/countries/${code}/states`;
464
+ spinnerText = `Fetching states for ${code}...`;
465
+ } else {
466
+ endpoint = "/states";
467
+ spinnerText = "Fetching all states...";
471
468
  }
472
- const spinner = await createSpinner(`Fetching states for ${code}...`, flags);
473
- const { data, usage } = await get(`/countries/${code}/states`);
469
+ const spinner = await createSpinner(spinnerText, flags);
470
+ const { data, usage } = await get(endpoint);
474
471
  spinner.stop();
475
472
  let states = data;
476
473
  if (options.filter) {
@@ -490,7 +487,7 @@ function registerSearchCommands(program2) {
490
487
  }
491
488
  printUsageFooter(usage, flags);
492
489
  });
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(
490
+ 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
491
  async (options, cmd) => {
495
492
  const globalOpts = cmd.optsWithGlobals();
496
493
  const flags = {
@@ -511,26 +508,18 @@ function registerSearchCommands(program2) {
511
508
  return;
512
509
  }
513
510
  }
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
- }
511
+ const stateCode = options.state?.toUpperCase();
512
+ let endpoint;
513
+ let spinnerText;
514
+ if (stateCode) {
515
+ endpoint = `/countries/${countryCode}/states/${stateCode}/cities`;
516
+ spinnerText = `Fetching cities for ${countryCode}/${stateCode}...`;
517
+ } else {
518
+ endpoint = `/countries/${countryCode}/cities`;
519
+ spinnerText = `Fetching all cities for ${countryCode}...`;
526
520
  }
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
- );
521
+ const spinner = await createSpinner(spinnerText, flags);
522
+ const { data, usage } = await get(endpoint);
534
523
  spinner.stop();
535
524
  let cities = data;
536
525
  if (options.filter) {
@@ -1328,7 +1317,7 @@ async function promptCountry2(countries) {
1328
1317
  }
1329
1318
  });
1330
1319
  }
1331
- async function promptState2(states) {
1320
+ async function promptState3(states) {
1332
1321
  return search2({
1333
1322
  message: "Select a state",
1334
1323
  source: (input) => {
@@ -1396,7 +1385,7 @@ async function runExploreSession(flags) {
1396
1385
  stderr(`No states found for ${countryIso}.`);
1397
1386
  return latestUsage;
1398
1387
  }
1399
- const stateIso = await promptState2(states);
1388
+ const stateIso = await promptState3(states);
1400
1389
  const selectedState = states.find((s) => s.iso2 === stateIso);
1401
1390
  const stateName = selectedState?.name ?? stateIso;
1402
1391
  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.5",
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",