Add support for -v

This commit is contained in:
Aoran Zeng 2024-06-05 09:24:39 +08:00
parent a823be73b6
commit 4936826635

View File

@ -3,7 +3,7 @@
* License : GPLv3 * License : GPLv3
* Authors : Aoran Zeng <ccmywish@qq.com> * Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-28> * Created on : <2023-08-28>
* Last modified : <2024-06-04> * Last modified : <2024-06-05>
* *
* chsrc: * chsrc:
* *
@ -12,7 +12,7 @@
* GPLv3 LICENSE.txt * GPLv3 LICENSE.txt
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
#define Chsrc_Version "v0.1.5-pre-2024/06/04" #define Chsrc_Version "v0.1.5-pre-2024/06/05"
#include "chsrc.h" #include "chsrc.h"
@ -2178,12 +2178,18 @@ print_supported_sources_for_target (SourceInfo sources[], size_t size)
} }
void
cli_print_version ()
{
puts (xy_strjoin (3, "chsrc: Change Source (GPLv3) ",
xy_str_to_magenta (Chsrc_Version), " by RubyMetric\n"));
}
void void
cli_print_help () cli_print_help ()
{ {
puts (xy_strjoin (3, "chsrc: Change Source (GPLv3) ", cli_print_version ();
xy_str_to_magenta (Chsrc_Version), " by RubyMetric\n"));
for (int i=0; i<xy_arylen(usage); i++) for (int i=0; i<xy_arylen(usage); i++)
{ {
puts (usage[i]); puts (usage[i]);
@ -2366,10 +2372,22 @@ main (int argc, char const *argv[])
xy_streql (command, "help") || xy_streql (command, "help") ||
xy_streql (command, "--help")) xy_streql (command, "--help"))
{ {
cli_print_version ();
cli_print_help (); cli_print_help ();
return 0; return 0;
} }
/* chsrc -v */
else if (xy_streql (command, "-v") ||
xy_streql (command, "-version") ||
xy_streql (command, "--version")||
xy_streql (command, "ver") ||
xy_streql (command, "version"))
{
cli_print_version ();
return 0;
}
/* chsrc list */ /* chsrc list */
else if (xy_streql (command, "list") || else if (xy_streql (command, "list") ||
xy_streql (command, "l") || xy_streql (command, "l") ||