From: Andreas Fenkart <afenkart@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 7/7] tools: env: update usage strings
Date: Thu, 26 Nov 2015 11:52:34 +0100 [thread overview]
Message-ID: <1448535154-6350-8-git-send-email-andreas.fenkart@dev.digitalstrom.org> (raw)
In-Reply-To: <1448535154-6350-1-git-send-email-andreas.fenkart@dev.digitalstrom.org>
Signed-off-by: Andreas Fenkart <andreas.fenkart@dev.digitalstrom.org>
---
tools/env/fw_env_main.c | 117 +++++++++++++++++++++++++++++++-----------------
1 file changed, 75 insertions(+), 42 deletions(-)
diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c
index e7ba95e..79273ce 100644
--- a/tools/env/fw_env_main.c
+++ b/tools/env/fw_env_main.c
@@ -36,12 +36,16 @@
#include <unistd.h>
#include "fw_env.h"
-#define CMD_PRINTENV "fw_printenv"
+#define CMD_PRINTENV "fw_printenv"
#define CMD_SETENV "fw_setenv"
+static int do_printenv;
static struct option long_options[] = {
- {"script", required_argument, NULL, 's'},
+ {"aes", required_argument, NULL, 'a'},
+ {"config", required_argument, NULL, 'c'},
{"help", no_argument, NULL, 'h'},
+ {"script", required_argument, NULL, 's'},
+ {"noheader", required_argument, NULL, 'n'},
{NULL, 0, NULL, 0}
};
@@ -49,36 +53,58 @@ struct common_args common_args;
struct printenv_args printenv_args;
struct setenv_args setenv_args;
-void usage(void)
+void usage_printenv(void)
{
- fprintf(stderr, "fw_printenv/fw_setenv, "
- "a command line interface to U-Boot environment\n\n"
-#ifndef CONFIG_FILE
- "usage:\tfw_printenv [-a key] [-n] [variable name]\n"
- "\tfw_setenv [-a key] [variable name] [variable value]\n"
-#else
- "usage:\tfw_printenv [-c /my/fw_env.config] [-a key] [-n] [variable name]\n"
- "\tfw_setenv [-c /my/fw_env.config] [-a key] [variable name] [variable value]\n"
+ fprintf(stderr,
+ "Usage: fw_printenv [OPTIONS]... [VARIABLE]...\n"
+ "Print variables from U-Boot environment\n"
+ "\n"
+ " -h, --help print this help.\n"
+#ifdef CONFIG_ENV_AES
+ " -a, --aes aes key to access environment\n"
#endif
- "\tfw_setenv -s [ file ]\n"
- "\tfw_setenv -s - < [ file ]\n\n"
- "The file passed as argument contains only pairs "
- "name / value\n"
- "Example:\n"
- "# Any line starting with # is treated as comment\n"
+#ifdef CONFIG_FILE
+ " -c, --config configuration file, default:" CONFIG_FILE "\n"
+#endif
+ " -n, --noheader do not repeat variable name in output\n"
+ "\n");
+}
+
+void usage_setenv(void)
+{
+ fprintf(stderr,
+ "Usage: fw_setenv [OPTIONS]... [VARIABLE]...\n"
+ "Modify variables in U-Boot environment\n"
+ "\n"
+ " -h, --help print this help.\n"
+#ifdef CONFIG_ENV_AES
+ " -a, --aes aes key to access environment\n"
+#endif
+#ifdef CONFIG_FILE
+ " -c, --config configuration file, default:" CONFIG_FILE "\n"
+#endif
+ " -s, --script batch mode to minimize writes\n"
+ "\n"
+ "Examples:\n"
+ " fw_setenv foo bar set variable foo equal bar\n"
+ " fw_setenv foo clear variable foo\n"
+ " fw_setenv --script file run batch script\n"
"\n"
- "\t netdev eth0\n"
- "\t kernel_addr 400000\n"
- "\t var1\n"
- "\t var2 The quick brown fox jumps over the "
- "lazy dog\n"
+ "Script Syntax:\n"
+ " key [space] value\n"
+ " lines starting with '#' are treated as commment\n"
"\n"
- "A variable without value will be dropped. It is possible\n"
- "to put any number of spaces between the fields, but any\n"
- "space inside the value is treated as part of the value "
- "itself.\n\n"
- );
+ " A variable without value will be deleted. Any number of spaces are\n"
+ " allowed between key and value. Space inside of the value is treated\n"
+ " as part of the value itself.\n"
+ "\n"
+ "Script Example:\n"
+ " netdev eth0\n"
+ " kernel_addr 400000\n"
+ " foo empty empty empty empty empty empty\n"
+ " bar\n"
+ "\n");
}
static void parse_common_args(int argc, char *argv[])
@@ -106,7 +132,7 @@ static void parse_common_args(int argc, char *argv[])
break;
#endif
case 'h':
- usage();
+ do_printenv ? usage_printenv() : usage_setenv();
exit(EXIT_SUCCESS);
break;
default:
@@ -138,7 +164,7 @@ int parse_printenv_args(int argc, char *argv[])
/* ignore common options */
break;
default: /* '?' */
- usage();
+ usage_printenv();
exit(EXIT_FAILURE);
break;
}
@@ -164,7 +190,7 @@ int parse_setenv_args(int argc, char *argv[])
/* ignore common options */
break;
default: /* '?' */
- usage();
+ usage_setenv();
exit(EXIT_FAILURE);
break;
}
@@ -174,27 +200,34 @@ int parse_setenv_args(int argc, char *argv[])
int main(int argc, char *argv[])
{
- char *cmdname = *argv;
const char *lockname = "/var/lock/" CMD_PRINTENV ".lock";
int lockfd = -1;
int retval = EXIT_SUCCESS;
+ char *_cmdname;
- if (strrchr(cmdname, '/') != NULL)
- cmdname = strrchr(cmdname, '/') + 1;
+ _cmdname = *argv;
+ if (strrchr(_cmdname, '/') != NULL)
+ _cmdname = strrchr(_cmdname, '/') + 1;
- if (strcmp(cmdname, CMD_PRINTENV) == 0) {
- if (parse_printenv_args(argc, argv))
- exit(EXIT_FAILURE);
- } else if (strcmp(cmdname, CMD_SETENV) == 0) {
- if (parse_setenv_args(argc, argv))
- exit(EXIT_FAILURE);
+ if (strcmp(_cmdname, CMD_PRINTENV) == 0) {
+ do_printenv = 1;
+ } else if (strcmp(_cmdname, CMD_SETENV) == 0) {
+ do_printenv = 0;
} else {
fprintf(stderr,
"Identity crisis - may be called as `%s' or as `%s' but not as `%s'\n",
- CMD_PRINTENV, CMD_SETENV, cmdname);
+ CMD_PRINTENV, CMD_SETENV, _cmdname);
exit(EXIT_FAILURE);
}
+ if (do_printenv) {
+ if (parse_printenv_args(argc, argv))
+ exit(EXIT_FAILURE);
+ } else {
+ if (parse_setenv_args(argc, argv))
+ exit(EXIT_FAILURE);
+ }
+
/* shift parsed flags, jump to non-option arguments */
argc -= optind;
argv += optind;
@@ -211,10 +244,10 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- if (strcmp(cmdname, CMD_PRINTENV) == 0) {
+ if (do_printenv) {
if (fw_printenv(argc, argv) != 0)
retval = EXIT_FAILURE;
- } else if (strcmp(cmdname, CMD_SETENV) == 0) {
+ } else {
if (!setenv_args.script_file) {
if (fw_setenv(argc, argv) != 0)
retval = EXIT_FAILURE;
--
2.6.2
prev parent reply other threads:[~2015-11-26 10:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-26 10:52 [U-Boot] [PATCH v2 0/7] tools: env: simplify argument parsing Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 1/7] tools: env validate: pass values as 0-based array Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 2/7] tools: env: make parse_aes_key stateless Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 3/7] tools: env: introduce setenv/printenv argument structs Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 4/7] tools: env: parse aes key / suppress flag into argument struct Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 5/7] tools: env: shift optind arguments and fix argument indices Andreas Fenkart
2015-11-26 10:52 ` [U-Boot] [PATCH v2 6/7] tools: env: factor out parse_common_args Andreas Fenkart
2015-11-26 10:52 ` Andreas Fenkart [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448535154-6350-8-git-send-email-andreas.fenkart@dev.digitalstrom.org \
--to=afenkart@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox