@countrystatecity/cli 0.1.4 → 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 +3 -0
  2. package/dist/index.js +12 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -55,6 +55,9 @@ 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"
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@countrystatecity/cli",
3
- "version": "0.1.4",
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",