You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config_cmd.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <errno.h>
  22. #include <getopt.h>
  23. #include <ipxe/command.h>
  24. #include <ipxe/parseopt.h>
  25. #include <ipxe/settings.h>
  26. #include <ipxe/settings_ui.h>
  27. FILE_LICENCE ( GPL2_OR_LATER );
  28. /** @file
  29. *
  30. * Configuration UI commands
  31. *
  32. */
  33. /** "config" options */
  34. struct config_options {};
  35. /** "config" option list */
  36. static struct option_descriptor config_opts[] = {};
  37. /** "config" command descriptor */
  38. static struct command_descriptor config_cmd =
  39. COMMAND_DESC ( struct config_options, config_opts, 0, 1, "[<scope>]" );
  40. /**
  41. * Parse settings scope name
  42. *
  43. * @v text Text
  44. * @ret value Integer value
  45. * @ret rc Return status code
  46. */
  47. static int parse_settings ( const char *text, struct settings **value ) {
  48. /* Sanity check */
  49. assert ( text != NULL );
  50. /* Parse scope name */
  51. *value = find_settings ( text );
  52. if ( ! *value ) {
  53. printf ( "\"%s\": no such scope\n", text );
  54. return -EINVAL;
  55. }
  56. return 0;
  57. }
  58. /**
  59. * "config" command
  60. *
  61. * @v argc Argument count
  62. * @v argv Argument list
  63. * @ret rc Return status code
  64. */
  65. static int config_exec ( int argc, char **argv ) {
  66. struct config_options opts;
  67. struct settings *settings;
  68. int rc;
  69. /* Parse options */
  70. if ( ( rc = parse_options ( argc, argv, &config_cmd, &opts ) ) != 0 )
  71. return rc;
  72. /* Parse settings option, if present */
  73. if ( ( rc = parse_settings ( ( ( optind < argc ) ? argv[optind] : "" ),
  74. &settings ) ) != 0 )
  75. return rc;
  76. /* Run settings UI */
  77. if ( ( rc = settings_ui ( settings ) ) != 0 ) {
  78. printf ( "Could not save settings: %s\n", strerror ( rc ) );
  79. return rc;
  80. }
  81. return 0;
  82. }
  83. /** Configuration UI commands */
  84. struct command config_command __command = {
  85. .name = "config",
  86. .exec = config_exec,
  87. };