1: <?php declare(strict_types=1);
2:
3: /**
4: * Clansuite Server Query
5: *
6: * SPDX-FileCopyrightText: 2003-2025 Jens A. Koch
7: * SPDX-License-Identifier: MIT
8: *
9: * For the full copyright and license information, please view
10: * the LICENSE file that was distributed with this source code.
11: */
12:
13: namespace Clansuite\Capture\CLI;
14:
15: use function in_array;
16:
17: /**
18: * Displays help information for the Clansuite Server Query capture tool CLI.
19: */
20: class HelpCommand
21: {
22: /**
23: * Executes the help command, printing usage information to stdout.
24: *
25: * @param array<string> $argv Command line arguments
26: *
27: * @return int Exit code (0 for success)
28: */
29: public function run(array $argv): int
30: {
31: // If the caller passed a known help flag as the second arg (e.g. '--help'),
32: // don't treat that as a message prefix to print. Only print a prefix
33: // when it's an actual message (like an error notice).
34: $maybe = $argv[1] ?? '';
35: $helpFlags = ['-h', '--help', 'help', null, ''];
36:
37: $prefix = in_array($maybe, $helpFlags, true) ? '' : $maybe;
38:
39: $this->printHelp($prefix);
40:
41: return 0;
42: }
43:
44: /**
45: * Prints the help text to stdout with an optional prefix.
46: *
47: * @param string $prefix Optional prefix to prepend to the help text
48: */
49: public function printHelp(string $prefix = ''): void
50: {
51: if ($prefix !== '') {
52: print $prefix;
53: }
54:
55: print "Clansuite Server Query - Capture Tool CLI\n";
56: print "Copyright (c) 2003-2025 Jens A. Koch.\n";
57: print "License: MIT.\n";
58: print "\n";
59: print "Description:\n";
60: print " A command-line tool to query and capture information from supported game servers.\n";
61: print "\n";
62: print "Usage:\n";
63: print " capture <ip> <query_port> [protocol] # Captures a fixture from server and stores it.\n";
64: print " capture list # Lists available fixtures.\n";
65: print " capture help|-h|--help # Shows this message.\n";
66: print "\n";
67: print "Arguments:\n";
68: print " <ip> IP address or hostname of the game server\n";
69: print " <port> Port number of the game server\n\n";
70: print "\n";
71: print "Examples:\n";
72: print " capture ger10.ddnet.org 8300 ddnet\n";
73: print " capture 123.123.123.123 8303 arma3\n";
74: print " capture list\n";
75: print " capture list ddnet | jq '.' # filter and pretty-print ddnet captures\n";
76: print "\n";
77: print "Notes:\n";
78: print " - Use -h or --help to show this message.\n";
79: }
80: }
81: