2 * Copyright 2015 Red Hat, Inc.
4 * SPDX-License-Identifier: LGPL-2.1-or-later
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 * Author: Matthias Clasen <mclasen@redhat.com>
30 static gboolean parent = FALSE;
32 static const GOptionEntry entries[] = {
33 { "parent", 'p', 0, G_OPTION_ARG_NONE, &parent, N_("Create parent directories"), NULL },
38 handle_mkdir (int argc, char *argv[], gboolean do_help)
40 GOptionContext *context;
47 g_set_prgname ("gio mkdir");
49 /* Translators: commandline placeholder */
50 param = g_strdup_printf ("%s…", _("LOCATION"));
51 context = g_option_context_new (param);
53 g_option_context_set_help_enabled (context, FALSE);
54 g_option_context_set_summary (context, _("Create directories."));
55 g_option_context_set_description (context,
56 _("gio mkdir is similar to the traditional mkdir utility, but using GIO\n"
57 "locations instead of local files: for example, you can use something\n"
58 "like smb://server/resource/mydir as location."));
59 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
63 show_help (context, NULL);
64 g_option_context_free (context);
68 if (!g_option_context_parse (context, &argc, &argv, &error))
70 show_help (context, error->message);
72 g_option_context_free (context);
78 show_help (context, _("No locations given"));
79 g_option_context_free (context);
83 g_option_context_free (context);
85 for (i = 1; i < argc; i++)
87 file = g_file_new_for_commandline_arg (argv[i]);
91 if (!g_file_make_directory_with_parents (file, NULL, &error))
93 print_file_error (file, error->message);
100 if (!g_file_make_directory (file, NULL, &error))
102 print_file_error (file, error->message);
103 g_error_free (error);
106 g_object_unref (file);