Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
lektor
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
b80455f2
Vérifiée
Valider
b80455f2
rédigé
5 years ago
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Embed help inside the lkt_cmd_opt
parent
0fa2e54c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!64
Resolve "Installation"
Modifications
3
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
inc/lektor/cmd.h
+4
-0
4 ajouts, 0 suppression
inc/lektor/cmd.h
src/cmd.c
+25
-0
25 ajouts, 0 suppression
src/cmd.c
src/main/lktadm.c
+11
-9
11 ajouts, 9 suppressions
src/main/lktadm.c
avec
40 ajouts
et
9 suppressions
inc/lektor/cmd.h
+
4
−
0
Voir le fichier @
b80455f2
...
...
@@ -17,8 +17,12 @@ typedef void (*lkt_cmd_callback)(struct lkt_cmd_args *);
struct
lkt_cmd_opt
{
const
char
*
name
;
lkt_cmd_callback
call
;
const
char
*
help
;
int
sub
;
};
/* Parse the command line with the list of options. No parameter may be NULL.
Does not return. */
noreturn
void
lkt_cmd_parse
(
struct
lkt_cmd_opt
*
opts
,
int
argc
,
const
char
**
argv
,
void
(
*
help
)(
void
));
void
lkt_cmd_help
(
struct
lkt_cmd_opt
*
opts
,
const
char
*
name
);
Ce diff est replié.
Cliquez pour l'agrandir.
src/cmd.c
+
25
−
0
Voir le fichier @
b80455f2
#define _POSIX_C_SOURCE 200809L
#include
<lektor/cmd.h>
#include
<lektor/macro.h>
#include
<sys/types.h>
#include
<stdlib.h>
#include
<strings.h>
#include
<string.h>
#include
<stdio.h>
#include
<unistd.h>
noreturn
void
lkt_cmd_parse
(
struct
lkt_cmd_opt
*
opts
,
int
argc
,
const
char
**
argv
,
void
(
*
help
)(
void
))
...
...
@@ -60,3 +62,26 @@ not_exclusive:
fprintf
(
stderr
,
"Failed to determine which option to choose, '%s' is not exclusive
\n
"
,
argv
[
0
]);
exit
(
EXIT_FAILURE
);
}
void
lkt_cmd_help
(
struct
lkt_cmd_opt
*
opts
,
const
char
*
name
)
{
struct
lkt_cmd_opt
*
it
=
opts
;
int
offset
=
0
,
max_len
=
1
;
/* Get the maximan argument len */
while
(
it
&&
it
->
name
)
{
int
len
=
strlen
(
it
->
name
);
max_len
=
MAX
(
max_len
,
len
);
it
=
opts
+
(
++
offset
);
}
/* Print the options */
it
=
opts
;
offset
=
0
;
printf
(
"COMMAND %s:
\n
"
,
name
);
while
(
it
&&
it
->
name
)
{
printf
(
"
\t
%*s %s
\n
"
,
max_len
,
it
->
name
,
it
->
help
);
it
=
opts
+
(
++
offset
);
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
src/main/lktadm.c
+
11
−
9
Voir le fichier @
b80455f2
...
...
@@ -278,10 +278,10 @@ download__(struct lkt_cmd_args *args)
}
static
struct
lkt_cmd_opt
options_init
[]
=
{
{
.
name
=
"database"
,
.
call
=
init_database__
},
{
.
name
=
"populate"
,
.
call
=
init_populate__
},
{
.
name
=
"metadata"
,
.
call
=
init_metadata__
},
{
.
name
=
"file"
,
.
call
=
init_file__
},
{
.
name
=
"database"
,
.
call
=
init_database__
,
.
help
=
"Create an empty database"
},
{
.
name
=
"populate"
,
.
call
=
init_populate__
,
.
help
=
"Populate database from kara on fs"
},
{
.
name
=
"metadata"
,
.
call
=
init_metadata__
,
.
help
=
"Set mdt for all kara in fs"
},
{
.
name
=
"file"
,
.
call
=
init_file__
,
.
help
=
"Set mdt for a kara by its path"
},
LKT_OPT_NULL
,
};
...
...
@@ -292,16 +292,18 @@ init__(struct lkt_cmd_args *args)
}
static
struct
lkt_cmd_opt
options
[]
=
{
{
.
name
=
"init"
,
.
call
=
init__
},
{
.
name
=
"get"
,
.
call
=
get__
,
},
{
.
name
=
"download"
,
.
call
=
download__
},
{
.
name
=
"cat"
,
.
call
=
cat__
,
},
{
.
name
=
"conf"
,
.
call
=
conf__
,
},
{
.
name
=
"init"
,
.
call
=
init__
,
.
help
=
"The init sub-command"
,
.
sub
=
1
},
{
.
name
=
"get"
,
.
call
=
get__
,
.
help
=
"Get the mdt of a kara by its id"
},
{
.
name
=
"download"
,
.
call
=
download__
,
.
help
=
"Download a kara by its id"
},
{
.
name
=
"cat"
,
.
call
=
cat__
,
.
help
=
"Prints the mdt of a kara on the fs"
},
{
.
name
=
"conf"
,
.
call
=
conf__
,
.
help
=
"Prints out the default config"
},
LKT_OPT_NULL
,
};
int
main
(
int
argc
,
const
char
**
argv
)
{
lkt_cmd_help
(
options
,
argv
[
0
]);
exit
(
0
);
lkt_cmd_parse
(
options
,
argc
-
1
,
argv
+
1
,
help
);
}
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter