@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.
- package/README.md +5 -1
- package/dist/index.js +14 -22
- 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
|
|
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
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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;
|