diff --git a/README.md b/README.md index 092fd39..01c4b10 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ In this version, normal option support five data types: `logical, integer, real, ```bash ls -l ``` -them `-l` option is set to `.true.`. To add the other four data type's options, you must give the default value, in case if one do not set the option, we use the default value. In command line, you should set the option like this: +them `-l` option is set to `.true.`. To add the other four data types' options, you must give the default value, in case if one do not set the option, it use the default value. In command line, you should set the option like this: ```bash greet --name Alice --age 24 ``` @@ -130,7 +130,7 @@ The corresponding callback subroutine is called immediately as long as the progr ### argument -`argument` is opposited to `option`. You must set it's value in command line. If not, the program will stop with error. `argument` also contains two types: position argument and named argument. +`argument` is opposited to `option`. You must set its value in command line. If not, the program will stop with error. `argument` also contains two types: position argument and named argument. In this version, `argument` supports `integer, real, real(kind=8), character(len=*)` data types. It does not support `logical` type, you should use `option` instead. #### position argument @@ -153,7 +153,7 @@ The named argument is defined by myself, it is designed for my work. It is used ```bash greet name=Alice age=24 ``` -It is tedious comparing with position argument, so it should not used in a common command line program. But it useful in a big project, and you run program with a shell script. In this case, the named argument make the script more readable. +It is tedious comparing with position argument, so it should not be used in a common command line program. But it is useful in a big project, and you run program with a shell script. In this case, the named argument make the script more readable. Add named argument like this: ```fortran @@ -209,7 +209,7 @@ call args%print_as_ini(stdout, .true.) ``` ### `print_uasge` && `set_program_name` -If you give none command line argument, the program will call `print_usage` and exit. It is just the first line of `print_help`. `set_program_name` only affects program name in `print_usage`, if you does not set it, it will use `argv[0]`. +If you give none command line argument and if it needs at least one argument, the program will call `print_usage` and exit. It is just the first line of `print_help`. `set_program_name` only affects program name in `print_usage`, if you does not set it, it will use `argv[0]`. ## Reference diff --git a/README_zh.md b/README_zh.md index f0f8e05..2b9b461 100644 --- a/README_zh.md +++ b/README_zh.md @@ -215,7 +215,7 @@ call args%print_as_ini(stdout, .true.) 这个函数的第二个参数表示是否打印注释,如果为`.true.`那么会把帮助信息打印为注释。 ### `print_uasge`和`set_program_name` -如果你运行程序不带任何命令行参数,那么`argparser`会调用`print_usage`并退出。`print_usage`实际上就是`print_help`的第一行信息,算是一个简短的帮助信息。`set_program_name`仅仅影响`print_usage`时显示的程序名字,如果不调用这个函数,那么会使用`argv[0]`。 +如果你运行程序不带任何命令行参数同时程序应该需要argument,那么`argparser`会调用`print_usage`并退出。`print_usage`实际上就是`print_help`的第一行信息,算是一个简短的帮助信息。`set_program_name`仅仅影响`print_usage`时显示的程序名字,如果不调用这个函数,那么会使用`argv[0]`。 ## 参考 diff --git a/src/argparse-f.f90 b/src/argparse-f.f90 index dac3102..b1b3771 100644 --- a/src/argparse-f.f90 +++ b/src/argparse-f.f90 @@ -1,6 +1,6 @@ ! MIT License -! Copyright (c) 2023 0382 +! Copyright (c) 2023 0382 and argparse-f's contributors ! Permission is hereby granted, free of charge, to any person obtaining a copy ! of this software and associated documentation files (the "Software"), to deal @@ -156,7 +156,7 @@ subroutine argp_parse(this) print "(A)", "WARNING: you get a truncated program name" end if end if - if (argc == 0) then + if (argc == 0 .and. (this%argument_size /= 0 .or. this%named_argument_size /= 0)) then call this%print_usage() stop end if