Userland: Port sleep(1) to Core::ArgsParser

This commit is contained in:
Sergey Bugaev 2020-05-26 13:35:09 +03:00 committed by Andreas Kling
parent 27360f1f20
commit 62283ade91
Notes: sideshowbarker 2024-07-19 06:07:23 +09:00

View File

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/String.h>
#include <LibCore/ArgsParser.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
@ -41,16 +41,12 @@ int main(int argc, char** argv)
return 1;
}
if (argc != 2) {
printf("usage: sleep <seconds>\n");
return 1;
}
bool ok;
unsigned secs = String(argv[1]).to_uint(ok);
if (!ok) {
fprintf(stderr, "Not a valid number of seconds: \"%s\"\n", argv[1]);
return 1;
}
int secs;
Core::ArgsParser args_parser;
args_parser.add_positional_argument(secs, "Number of seconds to sleep for", "num-seconds");
args_parser.parse(argc, argv);
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = handle_sigint;