summaryrefslogtreecommitdiffstats
path: root/fish
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-04 16:38:28 +0100
committerRichard Jones <rjones@redhat.com>2009-04-04 16:38:28 +0100
commit843514eef9dc6d04d71e031ba9ddb16e2beb9a04 (patch)
tree8318edc62b21e5823cfd5c4171d8a974571bc90d /fish
parenteb50cde931893e54c5aa9816cbca49e36891be8f (diff)
downloadlibguestfs-843514eef9dc6d04d71e031ba9ddb16e2beb9a04.tar.gz
libguestfs-843514eef9dc6d04d71e031ba9ddb16e2beb9a04.tar.xz
libguestfs-843514eef9dc6d04d71e031ba9ddb16e2beb9a04.zip
Implement RString and RStringList return types.
- implement 'll' command. - outlines for 'ls' and 'cat' commands.
Diffstat (limited to 'fish')
-rw-r--r--fish/cmds.c72
-rw-r--r--fish/fish.c19
-rw-r--r--fish/fish.h2
3 files changed, 93 insertions, 0 deletions
diff --git a/fish/cmds.c b/fish/cmds.c
index bc9d5a9c..3b53587b 100644
--- a/fish/cmds.c
+++ b/fish/cmds.c
@@ -29,6 +29,9 @@ void list_commands (void)
{
printf (" %-16s %s\n", "Command", "Description");
list_builtin_commands ();
+ printf ("%-20s %s\n", "cat", "list the files in a directory (long format)");
+ printf ("%-20s %s\n", "ll", "list the files in a directory (long format)");
+ printf ("%-20s %s\n", "ls", "list the files in a directory");
printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem");
printf ("%-20s %s\n", "sync", "sync disks, writes are flushed through to the disk image");
printf ("%-20s %s\n", "touch", "update file timestamps or create a new file");
@@ -37,6 +40,15 @@ void list_commands (void)
void display_command (const char *cmd)
{
+ if (strcasecmp (cmd, "cat") == 0)
+ pod2text ("cat - list the files in a directory (long format)", " cat <path>\n\nReturn the contents of the file named C<path>.\n\nBecause of the message protocol, there is a transfer limit \nof somewhere between 2MB and 4MB. To transfer large files you should use\nFTP.");
+ else
+ if (strcasecmp (cmd, "ll") == 0)
+ pod2text ("ll - list the files in a directory (long format)", " ll <directory>\n\nList the files in C<directory> (relative to the root directory,\nthere is no cwd) in the format of 'ls -la'.\n\nThis command is mostly useful for interactive sessions. It\nis I<not> intended that you try to parse the output string.");
+ else
+ if (strcasecmp (cmd, "ls") == 0)
+ pod2text ("ls - list the files in a directory", " ls <directory>\n\nList the files in C<directory> (relative to the root directory,\nthere is no cwd). The '.' and '..' entries are not returned, but\nhidden files are shown.\n\nThis command is mostly useful for interactive sessions.");
+ else
if (strcasecmp (cmd, "mount") == 0)
pod2text ("mount - mount a guest disk at a position in the filesystem", " mount <device> <mountpoint>\n\nMount a guest disk at a position in the filesystem. Block devices\nare named C</dev/sda>, C</dev/sdb> and so on, as they were added to\nthe guest. If those block devices contain partitions, they will have\nthe usual names (eg. C</dev/sda1>). Also LVM C</dev/VG/LV>-style\nnames can be used.\n\nThe rules are the same as for L<mount(2)>: A filesystem must\nfirst be mounted on C</> before others can be mounted. Other\nfilesystems can only be mounted on directories which already\nexist.\n\nThe mounted filesystem is writable, if we have sufficient permissions\non the underlying device.\n\nThe filesystem options C<sync> and C<noatime> are set with this\ncall, in order to improve reliability.");
else
@@ -49,6 +61,57 @@ void display_command (const char *cmd)
display_builtin_command (cmd);
}
+static int run_cat (const char *cmd, int argc, char *argv[])
+{
+ char *r;
+ const char *path;
+ if (argc != 1) {
+ fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ path = argv[0];
+ r = guestfs_cat (g, path);
+ if (r == NULL) return -1;
+ printf ("%s", r);
+ free (r);
+ return 0;
+}
+
+static int run_ll (const char *cmd, int argc, char *argv[])
+{
+ char *r;
+ const char *directory;
+ if (argc != 1) {
+ fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ directory = argv[0];
+ r = guestfs_ll (g, directory);
+ if (r == NULL) return -1;
+ printf ("%s", r);
+ free (r);
+ return 0;
+}
+
+static int run_ls (const char *cmd, int argc, char *argv[])
+{
+ char **r;
+ const char *directory;
+ if (argc != 1) {
+ fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ directory = argv[0];
+ r = guestfs_ls (g, directory);
+ if (r == NULL) return -1;
+ print_strings (r);
+ free_strings (r);
+ return 0;
+}
+
static int run_mount (const char *cmd, int argc, char *argv[])
{
int r;
@@ -93,6 +156,15 @@ static int run_touch (const char *cmd, int argc, char *argv[])
int run_action (const char *cmd, int argc, char *argv[])
{
+ if (strcasecmp (cmd, "cat") == 0)
+ return run_cat (cmd, argc, argv);
+ else
+ if (strcasecmp (cmd, "ll") == 0)
+ return run_ll (cmd, argc, argv);
+ else
+ if (strcasecmp (cmd, "ls") == 0)
+ return run_ls (cmd, argc, argv);
+ else
if (strcasecmp (cmd, "mount") == 0)
return run_mount (cmd, argc, argv);
else
diff --git a/fish/fish.c b/fish/fish.c
index 5c89335f..374416e7 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -526,3 +526,22 @@ parse_size (const char *str, off_t *size_rtn)
return 0;
}
+
+void
+free_strings (char **argv)
+{
+ int argc;
+
+ for (argc = 0; argv[argc] != NULL; ++argc)
+ free (argv[argc]);
+ free (argv);
+}
+
+void
+print_strings (char **argv)
+{
+ int argc;
+
+ for (argc = 0; argv[argc] != NULL; ++argc)
+ printf ("%s\n", argv[argc]);
+}
diff --git a/fish/fish.h b/fish/fish.h
index f98464a5..d398201b 100644
--- a/fish/fish.h
+++ b/fish/fish.h
@@ -29,6 +29,8 @@ extern int verbose;
extern void pod2text (const char *heading, const char *body);
extern void list_builtin_commands (void);
extern void display_builtin_command (const char *cmd);
+extern void free_strings (char **argv);
+extern void print_strings (char **argv);
/* in cmds.c (auto-generated) */
extern void list_commands (void);