OSDN Git Service

Diagnose invalid command arguments.
authorJim Meyering <jim@meyering.net>
Sat, 26 May 2007 04:59:34 +0000 (06:59 +0200)
committerJim Meyering <jim@meyering.net>
Sat, 26 May 2007 05:06:17 +0000 (07:06 +0200)
commit0c2d6ba0757324c3975cbf10868f266fe6dbbbfe
treeba73d406ac3f96a5ca407e712627af2e4de7ce25
parent95359ad0c816ea476adda38b81e72c94257c531d
Diagnose invalid command arguments.

This started because I objected to parted failing with no diagnostic
when given an invalid file system type:

    $ /sbin/parted -s $dev mklabel loop mkpartfs hfsplus 0 1.4
    WARNING: You are not superuser.  Watch out for permissions.
    [Exit 1]

With the changes below, it does this:

    $ ./parted -s $dev mklabel loop mkpartfs hfsplus 0 1.4
    ./parted: invalid token: hfsplus
    [Exit 1]

The following may look like a simple change, but looks are deceptive...
For example, if you try to diagnose via ped_exception_throw instead
of "error", you'll find that the mere fact of diagnosing the problem
introduces new ones because of how the exception handler manipulates the
global command line buffer containing the token we're complaining about.

But this isn't library code, so using error() is fine.

Diagnose invalid command arguments.
When a command argument doesn't match the expected candidate values,
parted would silently exit (in script mode) or simply act as if that
value and any following ones had not been specified (in interactive
mode).  With this change, it complains about the "invalid token",
and in script mode (where there hasn't been a prompt to give context)
sometimes tells what type of token it was expecting.
* parted/ui.c: Include "error.h".
(command_line_get_word): If the user's "token" wasn't a good enough
match, give a diagnostic.  In script mode, return NULL so that the
callers can give additional information.
* tests/t2000-mkfs.sh: New test for the above.
* tests/t0000-basic.sh: Expect the new diagnostic when "msdos" is
treated as an unrecognized first token after "mklabel".  This happens
when trying to label a disk that already has a label.
* tests/t1100-busy-label.sh: Likewise.
parted/ui.c
tests/t0000-basic.sh
tests/t1100-busy-label.sh
tests/t2000-mkfs.sh