mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 02:06:43 +00:00
refactor(scripts): share mobile version arg parsing
This commit is contained in:
@@ -1,51 +1,9 @@
|
||||
// Android Sync Versioning script supports OpenClaw repository automation.
|
||||
import path from "node:path";
|
||||
import { syncAndroidVersioning } from "./lib/android-version.ts";
|
||||
import { parseVersionSyncArgs } from "./lib/version-script-args.ts";
|
||||
|
||||
type Mode = "check" | "write";
|
||||
|
||||
export function parseArgs(argv: string[]): { help: boolean; mode: Mode; rootDir: string } {
|
||||
let help = false;
|
||||
let mode: Mode = "write";
|
||||
let rootDir = path.resolve(".");
|
||||
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
switch (arg) {
|
||||
case "--check": {
|
||||
mode = "check";
|
||||
break;
|
||||
}
|
||||
case "--write": {
|
||||
mode = "write";
|
||||
break;
|
||||
}
|
||||
case "--root": {
|
||||
rootDir = path.resolve(readOptionValue(argv, index, "--root"));
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
case "-h":
|
||||
case "--help": {
|
||||
help = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown argument: ${arg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { help, mode, rootDir };
|
||||
}
|
||||
|
||||
function readOptionValue(argv: string[], index: number, flag: string): string {
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith("--")) {
|
||||
throw new Error(`Missing value for ${flag}.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
export { parseVersionSyncArgs as parseArgs } from "./lib/version-script-args.ts";
|
||||
|
||||
function printUsage(): void {
|
||||
process.stdout.write(
|
||||
@@ -54,7 +12,7 @@ function printUsage(): void {
|
||||
}
|
||||
|
||||
function main(argv = process.argv.slice(2)): number {
|
||||
const options = parseArgs(argv);
|
||||
const options = parseVersionSyncArgs(argv);
|
||||
if (options.help) {
|
||||
printUsage();
|
||||
return 0;
|
||||
|
||||
@@ -1,63 +1,6 @@
|
||||
// Android Version script supports OpenClaw repository automation.
|
||||
import path from "node:path";
|
||||
import { resolveAndroidVersion } from "./lib/android-version.ts";
|
||||
|
||||
type CliOptions = {
|
||||
field: string | null;
|
||||
format: "json" | "shell";
|
||||
help: boolean;
|
||||
rootDir: string;
|
||||
};
|
||||
|
||||
function parseArgs(argv: string[]): CliOptions {
|
||||
let field: string | null = null;
|
||||
let format: "json" | "shell" = "json";
|
||||
let help = false;
|
||||
let rootDir = path.resolve(".");
|
||||
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
switch (arg) {
|
||||
case "--field": {
|
||||
field = readOptionValue(argv, index, "--field");
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
case "--json": {
|
||||
format = "json";
|
||||
break;
|
||||
}
|
||||
case "--shell": {
|
||||
format = "shell";
|
||||
break;
|
||||
}
|
||||
case "--root": {
|
||||
const value = readOptionValue(argv, index, "--root");
|
||||
rootDir = path.resolve(value);
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
case "-h":
|
||||
case "--help": {
|
||||
help = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown argument: ${arg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { field, format, help, rootDir };
|
||||
}
|
||||
|
||||
function readOptionValue(argv: string[], index: number, flag: string): string {
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith("--")) {
|
||||
throw new Error(`Missing value for ${flag}.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
import { parseVersionQueryArgs } from "./lib/version-script-args.ts";
|
||||
|
||||
function printUsage(): void {
|
||||
process.stdout.write(
|
||||
@@ -66,7 +9,7 @@ function printUsage(): void {
|
||||
}
|
||||
|
||||
function main(argv = process.argv.slice(2)): number {
|
||||
const options = parseArgs(argv);
|
||||
const options = parseVersionQueryArgs(argv);
|
||||
if (options.help) {
|
||||
printUsage();
|
||||
return 0;
|
||||
|
||||
@@ -1,51 +1,9 @@
|
||||
// Ios Sync Versioning script supports OpenClaw repository automation.
|
||||
import path from "node:path";
|
||||
import { syncIosVersioning } from "./lib/ios-version.ts";
|
||||
import { parseVersionSyncArgs } from "./lib/version-script-args.ts";
|
||||
|
||||
type Mode = "check" | "write";
|
||||
|
||||
export function parseArgs(argv: string[]): { help: boolean; mode: Mode; rootDir: string } {
|
||||
let help = false;
|
||||
let mode: Mode = "write";
|
||||
let rootDir = path.resolve(".");
|
||||
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
switch (arg) {
|
||||
case "--check": {
|
||||
mode = "check";
|
||||
break;
|
||||
}
|
||||
case "--write": {
|
||||
mode = "write";
|
||||
break;
|
||||
}
|
||||
case "--root": {
|
||||
rootDir = path.resolve(readOptionValue(argv, index, "--root"));
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
case "-h":
|
||||
case "--help": {
|
||||
help = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown argument: ${arg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { help, mode, rootDir };
|
||||
}
|
||||
|
||||
function readOptionValue(argv: string[], index: number, flag: string): string {
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith("--")) {
|
||||
throw new Error(`Missing value for ${flag}.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
export { parseVersionSyncArgs as parseArgs } from "./lib/version-script-args.ts";
|
||||
|
||||
function printUsage(): void {
|
||||
process.stdout.write(
|
||||
@@ -54,7 +12,7 @@ function printUsage(): void {
|
||||
}
|
||||
|
||||
function main(argv = process.argv.slice(2)): number {
|
||||
const options = parseArgs(argv);
|
||||
const options = parseVersionSyncArgs(argv);
|
||||
if (options.help) {
|
||||
printUsage();
|
||||
return 0;
|
||||
|
||||
+2
-59
@@ -1,63 +1,6 @@
|
||||
// Ios Version script supports OpenClaw repository automation.
|
||||
import path from "node:path";
|
||||
import { resolveIosVersion } from "./lib/ios-version.ts";
|
||||
|
||||
type CliOptions = {
|
||||
field: string | null;
|
||||
format: "json" | "shell";
|
||||
help: boolean;
|
||||
rootDir: string;
|
||||
};
|
||||
|
||||
function parseArgs(argv: string[]): CliOptions {
|
||||
let field: string | null = null;
|
||||
let format: "json" | "shell" = "json";
|
||||
let help = false;
|
||||
let rootDir = path.resolve(".");
|
||||
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
switch (arg) {
|
||||
case "--field": {
|
||||
field = readOptionValue(argv, index, "--field");
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
case "--json": {
|
||||
format = "json";
|
||||
break;
|
||||
}
|
||||
case "--shell": {
|
||||
format = "shell";
|
||||
break;
|
||||
}
|
||||
case "--root": {
|
||||
const value = readOptionValue(argv, index, "--root");
|
||||
rootDir = path.resolve(value);
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
case "-h":
|
||||
case "--help": {
|
||||
help = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown argument: ${arg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { field, format, help, rootDir };
|
||||
}
|
||||
|
||||
function readOptionValue(argv: string[], index: number, flag: string): string {
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith("--")) {
|
||||
throw new Error(`Missing value for ${flag}.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
import { parseVersionQueryArgs } from "./lib/version-script-args.ts";
|
||||
|
||||
function printUsage(): void {
|
||||
process.stdout.write(
|
||||
@@ -66,7 +9,7 @@ function printUsage(): void {
|
||||
}
|
||||
|
||||
function main(argv = process.argv.slice(2)): number {
|
||||
const options = parseArgs(argv);
|
||||
const options = parseVersionQueryArgs(argv);
|
||||
if (options.help) {
|
||||
printUsage();
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import path from "node:path";
|
||||
|
||||
export type VersionScriptFormat = "json" | "shell";
|
||||
export type VersionQueryCliOptions = {
|
||||
field: string | null;
|
||||
format: VersionScriptFormat;
|
||||
help: boolean;
|
||||
rootDir: string;
|
||||
};
|
||||
export type VersionSyncMode = "check" | "write";
|
||||
export type VersionSyncCliOptions = {
|
||||
help: boolean;
|
||||
mode: VersionSyncMode;
|
||||
rootDir: string;
|
||||
};
|
||||
|
||||
export function parseVersionQueryArgs(argv: string[]): VersionQueryCliOptions {
|
||||
let field: string | null = null;
|
||||
let format: VersionScriptFormat = "json";
|
||||
let help = false;
|
||||
let rootDir = path.resolve(".");
|
||||
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
switch (arg) {
|
||||
case "--field": {
|
||||
field = readOptionValue(argv, index, "--field");
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
case "--json": {
|
||||
format = "json";
|
||||
break;
|
||||
}
|
||||
case "--shell": {
|
||||
format = "shell";
|
||||
break;
|
||||
}
|
||||
case "--root": {
|
||||
const value = readOptionValue(argv, index, "--root");
|
||||
rootDir = path.resolve(value);
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
case "-h":
|
||||
case "--help": {
|
||||
help = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown argument: ${arg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { field, format, help, rootDir };
|
||||
}
|
||||
|
||||
export function parseVersionSyncArgs(argv: string[]): VersionSyncCliOptions {
|
||||
let help = false;
|
||||
let mode: VersionSyncMode = "write";
|
||||
let rootDir = path.resolve(".");
|
||||
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
switch (arg) {
|
||||
case "--check": {
|
||||
mode = "check";
|
||||
break;
|
||||
}
|
||||
case "--write": {
|
||||
mode = "write";
|
||||
break;
|
||||
}
|
||||
case "--root": {
|
||||
rootDir = path.resolve(readOptionValue(argv, index, "--root"));
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
case "-h":
|
||||
case "--help": {
|
||||
help = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown argument: ${arg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { help, mode, rootDir };
|
||||
}
|
||||
|
||||
function readOptionValue(argv: string[], index: number, flag: string): string {
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith("--")) {
|
||||
throw new Error(`Missing value for ${flag}.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
Reference in New Issue
Block a user