mirror of https://github.com/djcb/mu.git
* move config handling to mu-config, add --mode parameter for mkdir
This commit is contained in:
parent
fc64926c63
commit
2ef4ceb7ed
|
@ -471,15 +471,14 @@ cmd_mkdir (MuConfigOptions *opts)
|
||||||
return FALSE; /* shouldn't happen */
|
return FALSE; /* shouldn't happen */
|
||||||
|
|
||||||
if (!opts->params[1]) {
|
if (!opts->params[1]) {
|
||||||
g_printerr ("usage: mu mkdir <dir> [more dirs]\n");
|
g_printerr (
|
||||||
|
"usage: mu mkdir [-u,--mode=<mode>] <dir> [more dirs]\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 1;
|
i = 1;
|
||||||
while (opts->params[i]) {
|
while (opts->params[i]) {
|
||||||
MU_WRITE_LOG ("mu_maildir_mkdir (%s, 0755, FALSE)",
|
if (!mu_maildir_mkmdir (opts->params[i], opts->dirmode, FALSE))
|
||||||
opts->params[i]);
|
|
||||||
if (!mu_maildir_mkmdir (opts->params[i], 0755, FALSE))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
#include "mu-config.h"
|
#include "mu-config.h"
|
||||||
|
|
||||||
|
|
||||||
GOptionGroup*
|
static GOptionGroup*
|
||||||
mu_config_options_group_mu (MuConfigOptions *opts)
|
config_options_group_mu (MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
GOptionGroup *og;
|
GOptionGroup *og;
|
||||||
GOptionEntry entries[] = {
|
GOptionEntry entries[] = {
|
||||||
|
@ -56,8 +56,8 @@ mu_config_options_group_mu (MuConfigOptions *opts)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GOptionGroup*
|
static GOptionGroup*
|
||||||
mu_config_options_group_index (MuConfigOptions *opts)
|
config_options_group_index (MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
GOptionGroup *og;
|
GOptionGroup *og;
|
||||||
GOptionEntry entries[] = {
|
GOptionEntry entries[] = {
|
||||||
|
@ -78,8 +78,8 @@ mu_config_options_group_index (MuConfigOptions *opts)
|
||||||
return og;
|
return og;
|
||||||
}
|
}
|
||||||
|
|
||||||
GOptionGroup*
|
static GOptionGroup*
|
||||||
mu_config_options_group_find (MuConfigOptions *opts)
|
config_options_group_find (MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
GOptionGroup *og;
|
GOptionGroup *og;
|
||||||
GOptionEntry entries[] = {
|
GOptionEntry entries[] = {
|
||||||
|
@ -107,15 +107,25 @@ mu_config_options_group_find (MuConfigOptions *opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static GOptionGroup*
|
||||||
mu_config_init (MuConfigOptions *opts)
|
config_options_group_mkdir (MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
g_return_if_fail (opts);
|
GOptionGroup *og;
|
||||||
|
GOptionEntry entries[] = {
|
||||||
|
{"mode", 'p', 0, G_OPTION_ARG_INT, &opts->dirmode,
|
||||||
|
"set the mode (as in chmod), in octal notation", NULL},
|
||||||
|
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
/* start from zero */
|
og = g_option_group_new ("mkdir",
|
||||||
memset (opts, 0, sizeof(MuConfigOptions));
|
"options for the 'mkdir' command",
|
||||||
|
"", NULL, NULL);
|
||||||
|
g_option_group_add_entries (og, entries);
|
||||||
|
|
||||||
|
return og;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gchar*
|
static gchar*
|
||||||
guess_muhome (void)
|
guess_muhome (void)
|
||||||
{
|
{
|
||||||
|
@ -133,11 +143,48 @@ guess_muhome (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static gboolean
|
||||||
mu_config_set_defaults (MuConfigOptions *opts)
|
parse_params (MuConfigOptions *config, int *argcp, char ***argvp)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
GOptionContext *context;
|
||||||
|
gboolean rv;
|
||||||
|
|
||||||
|
context = g_option_context_new ("- maildir utilities");
|
||||||
|
|
||||||
|
g_option_context_set_main_group (context,
|
||||||
|
config_options_group_mu (config));
|
||||||
|
g_option_context_add_group (context,
|
||||||
|
config_options_group_index (config));
|
||||||
|
g_option_context_add_group (context,
|
||||||
|
config_options_group_find (config));
|
||||||
|
g_option_context_add_group (context,
|
||||||
|
config_options_group_mkdir (config));
|
||||||
|
|
||||||
|
rv = g_option_context_parse (context, argcp, argvp, &error);
|
||||||
|
if (!rv) {
|
||||||
|
g_printerr ("error in options: %s\n", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
} else
|
||||||
|
g_option_context_free (context);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mu_config_init (MuConfigOptions *opts, int *argcp, char ***argvp)
|
||||||
{
|
{
|
||||||
gchar *old;
|
gchar *old;
|
||||||
g_return_if_fail (opts);
|
|
||||||
|
g_return_if_fail (opts);
|
||||||
|
memset (opts, 0, sizeof(MuConfigOptions));
|
||||||
|
|
||||||
|
/* set dirmode before, because '0000' is a valid mode */
|
||||||
|
opts->dirmode = 0755;
|
||||||
|
|
||||||
|
if (!parse_params (opts, argcp, argvp))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
if (!opts->muhome)
|
if (!opts->muhome)
|
||||||
opts->muhome = guess_muhome ();
|
opts->muhome = guess_muhome ();
|
||||||
|
@ -153,7 +200,7 @@ mu_config_set_defaults (MuConfigOptions *opts)
|
||||||
else
|
else
|
||||||
opts->maildir = mu_util_guess_maildir();
|
opts->maildir = mu_util_guess_maildir();
|
||||||
g_free (old);
|
g_free (old);
|
||||||
|
|
||||||
/* querying */
|
/* querying */
|
||||||
|
|
||||||
/* note, when no fields are specified, we use
|
/* note, when no fields are specified, we use
|
||||||
|
@ -170,8 +217,9 @@ mu_config_set_defaults (MuConfigOptions *opts)
|
||||||
opts->linksdir = mu_util_dir_expand (opts->linksdir);
|
opts->linksdir = mu_util_dir_expand (opts->linksdir);
|
||||||
g_free(old);
|
g_free(old);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_config_uninit (MuConfigOptions *opts)
|
mu_config_uninit (MuConfigOptions *opts)
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#define __MU_CONFIG_H__
|
#define __MU_CONFIG_H__
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <sys/types.h> /* for mode_t */
|
||||||
|
|
||||||
#include "mu-msg-fields.h"
|
#include "mu-msg-fields.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
@ -54,6 +56,9 @@ struct _MuConfigOptions {
|
||||||
gboolean clearlinks; /* clear a linksdir before filling */
|
gboolean clearlinks; /* clear a linksdir before filling */
|
||||||
|
|
||||||
gboolean descending; /* sort descending? */
|
gboolean descending; /* sort descending? */
|
||||||
|
|
||||||
|
/* options for mkdir */
|
||||||
|
mode_t dirmode; /* mode for the created maildir */
|
||||||
};
|
};
|
||||||
typedef struct _MuConfigOptions MuConfigOptions;
|
typedef struct _MuConfigOptions MuConfigOptions;
|
||||||
|
|
||||||
|
@ -65,14 +70,8 @@ typedef struct _MuConfigOptions MuConfigOptions;
|
||||||
*
|
*
|
||||||
* @param opts options
|
* @param opts options
|
||||||
*/
|
*/
|
||||||
void mu_config_init (MuConfigOptions *opts);
|
gboolean mu_config_init (MuConfigOptions *opts, int *argcp, char ***argvp);
|
||||||
|
|
||||||
/**
|
|
||||||
* fill unset config options with defaults
|
|
||||||
*
|
|
||||||
* @param opts options
|
|
||||||
*/
|
|
||||||
void mu_config_set_defaults (MuConfigOptions *opts);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* free the MuOptionsCOnfig structure; the the muhome and maildir
|
* free the MuOptionsCOnfig structure; the the muhome and maildir
|
||||||
|
@ -82,33 +81,6 @@ void mu_config_set_defaults (MuConfigOptions *opts);
|
||||||
*/
|
*/
|
||||||
void mu_config_uninit (MuConfigOptions *opts);
|
void mu_config_uninit (MuConfigOptions *opts);
|
||||||
|
|
||||||
/**
|
|
||||||
* get the general options option group
|
|
||||||
*
|
|
||||||
* @param opts the MuConfigOptions to fill from this option group
|
|
||||||
*
|
|
||||||
* @return a new option group; *DON'T* unref when added to an optioncontext
|
|
||||||
*/
|
|
||||||
GOptionGroup* mu_config_options_group_mu (MuConfigOptions *opts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the index-options option group
|
|
||||||
*
|
|
||||||
* @param opts the MuConfigOptions to fill from this option group
|
|
||||||
*
|
|
||||||
* @return a new option group; *DON'T* unref when added to an optioncontext
|
|
||||||
*/
|
|
||||||
GOptionGroup* mu_config_options_group_index (MuConfigOptions *opts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the find-options option group
|
|
||||||
*
|
|
||||||
* @param opts the MuConfigOptions to fill from this option group
|
|
||||||
*
|
|
||||||
* @return a new option group; *DON'T* unref when added to an optioncontext
|
|
||||||
*/
|
|
||||||
GOptionGroup* mu_config_options_group_find (MuConfigOptions *opts);
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
52
src/mu.c
52
src/mu.c
|
@ -46,34 +46,6 @@ init_log (MuConfigOptions *opts)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
parse_params (MuConfigOptions *config, int *argcp, char ***argvp)
|
|
||||||
{
|
|
||||||
GError *error = NULL;
|
|
||||||
GOptionContext *context;
|
|
||||||
gboolean rv;
|
|
||||||
|
|
||||||
context = g_option_context_new ("- maildir utilities");
|
|
||||||
|
|
||||||
g_option_context_set_main_group (context,
|
|
||||||
mu_config_options_group_mu (config));
|
|
||||||
g_option_context_add_group (context,
|
|
||||||
mu_config_options_group_index (config));
|
|
||||||
g_option_context_add_group (context,
|
|
||||||
mu_config_options_group_find (config));
|
|
||||||
|
|
||||||
rv = g_option_context_parse (context, argcp, argvp, &error);
|
|
||||||
if (!rv) {
|
|
||||||
g_printerr ("error in options: %s\n", error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
} else {
|
|
||||||
g_option_context_free (context);
|
|
||||||
mu_config_set_defaults (config);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
|
@ -83,23 +55,17 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
mu_config_init (&config);
|
if (!mu_config_init (&config, &argc, &argv))
|
||||||
|
return 1;
|
||||||
do {
|
|
||||||
rv = FALSE;
|
|
||||||
|
|
||||||
if (!parse_params (&config, &argc, &argv))
|
if (!init_log (&config)) {
|
||||||
break;
|
mu_config_uninit (&config);
|
||||||
|
return 1;
|
||||||
if (!init_log (&config))
|
}
|
||||||
break;
|
|
||||||
|
rv = mu_cmd_execute (&config);
|
||||||
rv = mu_cmd_execute (&config);
|
|
||||||
|
|
||||||
mu_log_uninit();
|
|
||||||
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
|
mu_log_uninit();
|
||||||
mu_config_uninit (&config);
|
mu_config_uninit (&config);
|
||||||
|
|
||||||
return rv ? 0 : 1;
|
return rv ? 0 : 1;
|
||||||
|
|
Loading…
Reference in New Issue