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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <errno.h>
  21. #include <getopt.h>
  22. #include <ipxe/command.h>
  23. #include <ipxe/parseopt.h>
  24. #include <ipxe/settings.h>
  25. #include <ipxe/settings_ui.h>
  26. FILE_LICENCE ( GPL2_OR_LATER );
  27. /** @file
  28. *
  29. * Configuration UI commands
  30. *
  31. */
  32. /** "config" options */
  33. struct config_options {};
  34. /** "config" option list */
  35. static struct option_descriptor config_opts[] = {};
  36. /** "config" command descriptor */
  37. static struct command_descriptor config_cmd =
  38. COMMAND_DESC ( struct config_options, config_opts, 0, 1, "[<scope>]" );
  39. /**
  40. * Parse settings scope name
  41. *
  42. * @v text Text
  43. * @ret value Integer value
  44. * @ret rc Return status code
  45. */
  46. static int parse_settings ( const char *text, struct settings **value ) {
  47. /* Sanity check */
  48. assert ( text != NULL );
  49. /* Parse scope name */
  50. *value = find_settings ( text );
  51. if ( ! *value ) {
  52. printf ( "\"%s\": no such scope\n", text );
  53. return -EINVAL;
  54. }
  55. return 0;
  56. }
  57. /**
  58. * "config" command
  59. *
  60. * @v argc Argument count
  61. * @v argv Argument list
  62. * @ret rc Return status code
  63. */
  64. static int config_exec ( int argc, char **argv ) {
  65. struct config_options opts;
  66. struct settings *settings;
  67. int rc;
  68. /* Parse options */
  69. if ( ( rc = parse_options ( argc, argv, &config_cmd, &opts ) ) != 0 )
  70. return rc;
  71. /* Parse settings option, if present */
  72. if ( ( rc = parse_settings ( ( ( optind < argc ) ? argv[optind] : "" ),
  73. &settings ) ) != 0 )
  74. return rc;
  75. /* Run settings UI */
  76. if ( ( rc = settings_ui ( settings ) ) != 0 ) {
  77. printf ( "Could not save settings: %s\n", strerror ( rc ) );
  78. return rc;
  79. }
  80. return 0;
  81. }
  82. /** Configuration UI commands */
  83. struct command config_command __command = {
  84. .name = "config",
  85. .exec = config_exec,
  86. };