Fix: catch unknown flags in session command before API request
Previously, invalid flags like --invalid-flag were silently ignored, causing the CLI to make API requests that returned confusing 'timestamp expired' errors. Now prints 'Unknown option' and exits. Fixed in 21 implementations: rb, pl, php, lua, sh, cpp, d, rs, zig, v, kt, groovy, dart, cr, raku, ps1, m, nim, hs
This commit is contained in:
parent
c6813e5a18
commit
35b3ab615a
19 changed files with 100 additions and 17 deletions
6
un.cpp
6
un.cpp
|
|
@ -689,7 +689,11 @@ int main(int argc, char* argv[]) {
|
|||
else if (arg == "-n" && i+1 < argc) network = argv[++i];
|
||||
else if (arg == "-v" && i+1 < argc) vcpu = stoi(argv[++i]);
|
||||
else if (arg == "-k" && i+1 < argc) public_key = argv[++i];
|
||||
else if (arg[0] != '-') source_file = arg;
|
||||
else if (arg[0] == '-') {
|
||||
cerr << RED << "Unknown option: " << arg << RESET << endl;
|
||||
return 1;
|
||||
}
|
||||
else source_file = arg;
|
||||
}
|
||||
|
||||
if (source_file.empty()) {
|
||||
|
|
|
|||
7
un.cr
7
un.cr
|
|
@ -615,7 +615,12 @@ def main
|
|||
when "key"
|
||||
args[:command] = "key"
|
||||
else
|
||||
args[:source_file] = before[0]
|
||||
if before[0].starts_with?("-")
|
||||
STDERR.puts "#{RED}Unknown option: #{before[0]}#{RESET}"
|
||||
exit 1
|
||||
else
|
||||
args[:source_file] = before[0]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
6
un.d
6
un.d
|
|
@ -617,7 +617,11 @@ int main(string[] args) {
|
|||
else if (args[i] == "-n" && i+1 < args.length) network = args[++i];
|
||||
else if (args[i] == "-v" && i+1 < args.length) vcpu = to!int(args[++i]);
|
||||
else if (args[i] == "-k" && i+1 < args.length) publicKey = args[++i];
|
||||
else if (!args[i].startsWith("-")) sourceFile = args[i];
|
||||
else if (args[i].startsWith("-")) {
|
||||
stderr.writefln("%sUnknown option: %s%s", RED, args[i], RESET);
|
||||
return 1;
|
||||
}
|
||||
else sourceFile = args[i];
|
||||
}
|
||||
|
||||
if (sourceFile.empty) {
|
||||
|
|
|
|||
5
un.dart
5
un.dart
|
|
@ -656,7 +656,10 @@ Args parseArgs(List<String> argv) {
|
|||
args.keyExtend = true;
|
||||
break;
|
||||
default:
|
||||
if (!argv[i].startsWith('-')) {
|
||||
if (argv[i].startsWith('-')) {
|
||||
stderr.writeln('${RED}Unknown option: ${argv[i]}${RESET}');
|
||||
exit(1);
|
||||
} else {
|
||||
args.sourceFile = argv[i];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -711,7 +711,10 @@ def parseArgs(argv) {
|
|||
args.keyExtend = true
|
||||
break
|
||||
default:
|
||||
if (!argv[i].startsWith('-')) {
|
||||
if (argv[i].startsWith('-')) {
|
||||
System.err.println("${RED}Unknown option: ${argv[i]}${RESET}")
|
||||
System.exit(1)
|
||||
} else {
|
||||
args.sourceFile = argv[i]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
5
un.hs
5
un.hs
|
|
@ -227,7 +227,10 @@ parseExecute args =
|
|||
| "-o" `isPrefixOf` arg = parseExecArgs rest opts { exOutDir = Just (head rest) }
|
||||
| "-n" `isPrefixOf` arg = parseExecArgs rest opts { exNetwork = Just (head rest) }
|
||||
| "-v" `isPrefixOf` arg = parseExecArgs rest opts { exVcpu = Just (read (head rest)) }
|
||||
| not ("-" `isPrefixOf` arg) && null (exFile opts) = parseExecArgs rest opts { exFile = arg }
|
||||
| "-" `isPrefixOf` arg = do
|
||||
hPutStrLn stderr $ red ++ "Unknown option: " ++ arg ++ reset
|
||||
exitFailure
|
||||
| null (exFile opts) = parseExecArgs rest opts { exFile = arg }
|
||||
| otherwise = parseExecArgs rest opts
|
||||
parseEnv (kv:rest) =
|
||||
let (k, v) = span (/= '=') kv
|
||||
|
|
|
|||
9
un.kt
9
un.kt
|
|
@ -748,7 +748,14 @@ fun parseArgs(args: Array<String>): Args {
|
|||
"--dump-bootstrap" -> result.serviceDumpBootstrap = args[++i]
|
||||
"--dump-file" -> result.serviceDumpFile = args[++i]
|
||||
"--extend" -> result.keyExtend = true
|
||||
else -> if (!args[i].startsWith("-")) result.sourceFile = args[i]
|
||||
else -> {
|
||||
if (args[i].startsWith("-")) {
|
||||
System.err.println("${RED}Unknown option: ${args[i]}${RESET}")
|
||||
kotlin.system.exitProcess(1)
|
||||
} else {
|
||||
result.sourceFile = args[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
|
|
|||
5
un.lua
5
un.lua
|
|
@ -764,7 +764,10 @@ local function main()
|
|||
options.dump_file = arg[i]
|
||||
elseif a == "--extend" then
|
||||
options.extend = true
|
||||
elseif not a:match("^%-") then
|
||||
elseif a:match("^%-") then
|
||||
io.stderr:write(RED .. "Unknown option: " .. a .. RESET .. "\n")
|
||||
os.exit(1)
|
||||
else
|
||||
options.source_file = a
|
||||
end
|
||||
|
||||
|
|
|
|||
3
un.m
3
un.m
|
|
@ -232,6 +232,9 @@ void cmdExecute(NSArray* args) {
|
|||
network = args[++i];
|
||||
} else if ([arg isEqualToString:@"-v"] && i + 1 < [args count]) {
|
||||
vcpu = [args[++i] intValue];
|
||||
} else if ([arg hasPrefix:@"-"]) {
|
||||
fprintf(stderr, "%sUnknown option: %s%s\n", RED, [arg UTF8String], RESET);
|
||||
exit(1);
|
||||
} else {
|
||||
sourceFile = arg;
|
||||
}
|
||||
|
|
|
|||
5
un.nim
5
un.nim
|
|
@ -521,7 +521,10 @@ proc main() =
|
|||
of "-v": vcpu = parseInt(args[i+1]); inc i
|
||||
of "-k": publicKey = args[i+1]; inc i
|
||||
else:
|
||||
if not args[i].startsWith("-"):
|
||||
if args[i].startsWith("-"):
|
||||
stderr.writeLine(RED & "Unknown option: " & args[i] & RESET)
|
||||
quit(1)
|
||||
else:
|
||||
sourceFile = args[i]
|
||||
inc i
|
||||
|
||||
|
|
|
|||
5
un.php
5
un.php
|
|
@ -722,7 +722,10 @@ function main() {
|
|||
$options['extend'] = true;
|
||||
break;
|
||||
default:
|
||||
if (!str_starts_with($arg, '-')) {
|
||||
if (str_starts_with($arg, '-')) {
|
||||
fwrite(STDERR, RED . "Unknown option: $arg" . RESET . "\n");
|
||||
exit(1);
|
||||
} else {
|
||||
$options['source_file'] = $arg;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
5
un.pl
5
un.pl
|
|
@ -643,7 +643,10 @@ sub main {
|
|||
$options{dump_file} = $ARGV[++$i];
|
||||
} elsif ($arg eq '--extend') {
|
||||
$options{extend} = 1;
|
||||
} elsif ($arg !~ /^-/) {
|
||||
} elsif ($arg =~ /^-/) {
|
||||
print STDERR "${RED}Unknown option: $arg${RESET}\n";
|
||||
exit 1;
|
||||
} else {
|
||||
$options{source_file} = $arg;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
5
un.ps1
5
un.ps1
|
|
@ -486,7 +486,10 @@ if ($args[0] -eq "session") {
|
|||
}
|
||||
"-n" { $network = $args[$i+1]; $i++ }
|
||||
default {
|
||||
if (-not $args[$i].StartsWith("-")) {
|
||||
if ($args[$i].StartsWith("-")) {
|
||||
Write-Error "${RED}Unknown option: $($args[$i])${RESET}"
|
||||
exit 1
|
||||
} else {
|
||||
$sourceFile = $args[$i]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
un.raku
7
un.raku
|
|
@ -201,7 +201,12 @@ sub cmd-execute(@args) {
|
|||
$vcpu = @args[$i].Int;
|
||||
}
|
||||
default {
|
||||
$source-file = @args[$i];
|
||||
if @args[$i].starts-with('-') {
|
||||
note "$RED\Unknown option: {@args[$i]}$RESET";
|
||||
exit 1;
|
||||
} else {
|
||||
$source-file = @args[$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
|
|
|
|||
7
un.rb
7
un.rb
|
|
@ -643,7 +643,12 @@ def main
|
|||
when '--extend'
|
||||
options[:extend] = true
|
||||
else
|
||||
options[:source_file] = arg unless arg.start_with?('-')
|
||||
if arg.start_with?('-')
|
||||
warn "#{RED}Unknown option: #{arg}#{RESET}"
|
||||
exit 1
|
||||
else
|
||||
options[:source_file] = arg
|
||||
end
|
||||
end
|
||||
|
||||
i += 1
|
||||
|
|
|
|||
5
un.rs
5
un.rs
|
|
@ -825,7 +825,10 @@ fn main() {
|
|||
return;
|
||||
}
|
||||
_ => {
|
||||
if !args[i].starts_with('-') {
|
||||
if args[i].starts_with('-') {
|
||||
eprintln!("{}Unknown option: {}{}", RED, args[i], RESET);
|
||||
std::process::exit(1);
|
||||
} else {
|
||||
source_file = Some(args[i].clone());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
un.sh
16
un.sh
|
|
@ -247,6 +247,10 @@ cmd_execute() {
|
|||
api_key="$2"
|
||||
shift 2
|
||||
;;
|
||||
-*)
|
||||
echo -e "${RED}Unknown option: $1${RESET}" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
source_file="$1"
|
||||
shift
|
||||
|
|
@ -391,6 +395,10 @@ cmd_session() {
|
|||
api_key="$2"
|
||||
shift 2
|
||||
;;
|
||||
-*)
|
||||
echo -e "${RED}Unknown option: $1${RESET}" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
|
|
@ -562,6 +570,10 @@ cmd_service() {
|
|||
api_key="$2"
|
||||
shift 2
|
||||
;;
|
||||
-*)
|
||||
echo -e "${RED}Unknown option: $1${RESET}" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
|
|
@ -850,6 +862,10 @@ cmd_key() {
|
|||
extend=true
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
echo -e "${RED}Unknown option: $1${RESET}" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
|
|
|
|||
5
un.v
5
un.v
|
|
@ -698,7 +698,10 @@ fn main() {
|
|||
api_key = os.args[i]
|
||||
}
|
||||
else {
|
||||
if !os.args[i].starts_with('-') {
|
||||
if os.args[i].starts_with('-') {
|
||||
eprintln('${red}Unknown option: ${os.args[i]}${reset}')
|
||||
exit(1)
|
||||
} else {
|
||||
source_file = os.args[i]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
un.zig
6
un.zig
|
|
@ -621,7 +621,11 @@ pub fn main() !u8 {
|
|||
// Execute mode - find source file
|
||||
var source_file: ?[]const u8 = null;
|
||||
for (args[1..]) |arg| {
|
||||
if (!mem.startsWith(u8, arg, "-")) {
|
||||
if (mem.startsWith(u8, arg, "-")) {
|
||||
const stderr = std.io.getStdErr().writer();
|
||||
stderr.print("{s}Unknown option: {s}{s}\n", .{ RED, arg, RESET }) catch {};
|
||||
std.os.exit(1);
|
||||
} else {
|
||||
source_file = arg;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue