Add some more cases to the app-id unit tests
[glib.git] / gio / gio-tool-rename.c
blobc27d668af16390de8ca1dd296b9996128e894437
1 /*
2 * Copyright 2015 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Matthias Clasen <mclasen@redhat.com>
20 #include "config.h"
22 #include <gio/gio.h>
23 #include <gi18n.h>
25 #include "gio-tool.h"
28 static const GOptionEntry entries[] = {
29 { NULL }
32 int
33 handle_rename (int argc, char *argv[], gboolean do_help)
35 GOptionContext *context;
36 GError *error = NULL;
37 GFile *file;
38 GFile *new_file;
39 int retval = 0;
40 gchar *param;
42 g_set_prgname ("gio rename");
44 /* Translators: commandline placeholder */
45 param = g_strdup_printf ("%s %s", _("LOCATION"), _("NAME"));
46 context = g_option_context_new (param);
47 g_free (param);
48 g_option_context_set_help_enabled (context, FALSE);
50 g_option_context_set_summary (context, _("Rename a file."));
51 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
53 if (do_help)
55 show_help (context, NULL);
56 return 0;
59 if (!g_option_context_parse (context, &argc, &argv, &error))
61 show_help (context, error->message);
62 g_error_free (error);
63 return 1;
66 if (argc < 3)
68 show_help (context, _("Missing argument"));
69 return 1;
71 if (argc > 3)
73 show_help (context, _("Too many arguments"));
74 return 1;
77 g_option_context_free (context);
79 file = g_file_new_for_commandline_arg (argv[1]);
80 new_file = g_file_set_display_name (file, argv[2], NULL, &error);
82 if (new_file == NULL)
84 g_printerr (_("Error: %s\n"), error->message);
85 g_error_free (error);
86 retval = 1;
88 else
90 char *uri = g_file_get_uri (new_file);
91 g_print (_("Rename successful. New uri: %s\n"), uri);
92 g_object_unref (new_file);
93 g_free (uri);
96 g_object_unref (file);
98 return retval;