@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.
- package/README.md +8 -1
- package/dist/index.js +26 -37
- 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
|
|
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
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
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(
|
|
473
|
-
const { data, usage } = await get(
|
|
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
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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;
|