Method: Yast::CommandLineClass#ProcessSystemCommands
- Defined in:
- library/commandline/src/modules/CommandLine.rb
#ProcessSystemCommands(command) ⇒ Object
Handle the system-wide commands, like help etc.
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
# File 'library/commandline/src/modules/CommandLine.rb', line 876 def ProcessSystemCommands(command) command = deep_copy(command) # handle help for specific command # this needs to be before general help, so "help help" works if Ops.get(command, ["options", "help"]) PrintHead() PrintActionHelp(Ops.get_string(command, "command", "")) return true end # Process command "interactive" if Ops.get_string(command, "command", "") == "interactive" @interactive = true return true end # Process command "exit" if Ops.get_string(command, "command", "") == "exit" @done = true @aborted = false return true end # Process command "abort" if Ops.get_string(command, "command", "") == "abort" @done = true @aborted = true return true end if Ops.get_string(command, "command", "") == "help" # don't print header when custom help is defined PrintHead() if !Builtins.haskey(@modulecommands, "customhelp") PrintGeneralHelp() return true end if Ops.get_string(command, "command", "") == "longhelp" PrintHead() PrintGeneralHelp() Builtins.foreach(Ops.get_map(@allcommands, "actions", {})) do |action, _def| PrintActionHelp(action) end return true end if Ops.get_string(command, "command", "") == "xmlhelp" if Builtins.haskey(Ops.get_map(command, "options", {}), "xmlfile") == false # error message - command line option xmlfile is missing Print( _( "Target file name ('xmlfile' option) is missing. Use xmlfile=<target_XML_file> command line option." ) ) return false end xmlfilename = Ops.get_string(command, ["options", "xmlfile"], "") if xmlfilename.nil? || xmlfilename == "" # error message - command line option xmlfile is missing Print( _( "Target file name ('xmlfile' option) is empty. Use xmlfile=<target_XML_file> command line option." ) ) return false end doc = {} # TODO: DTD specification Ops.set( doc, "listEntries", "commands" => "command", "options" => "option", "examples" => "example" ) # doc["cdataSections"] = []; Ops.set( doc, "systemID", Ops.add(Directory.schemadir, "/commandline.dtd") ) # doc["nameSpace"] = "http://www.suse.com/1.0/yast2ns"; Ops.set(doc, "typeNamespace", "http://www.suse.com/1.0/configns") Ops.set(doc, "rootElement", "commandline") XML.xmlCreateDoc(:xmlhelp, doc) exportmap = {} commands = [] actions = Ops.get_map(@cmdlinespec, "actions", {}) mappings = Ops.get_map(@cmdlinespec, "mappings", {}) = Ops.get_map(@cmdlinespec, "options", {}) Builtins.y2debug("cmdlinespec: %1", @cmdlinespec) Builtins.foreach(actions) do |action, description| help = "" # help text might be a simple string or a multiline text (list<string>) help_value = Ops.get(description, "help") if Ops.is_string?(help_value) help = Convert.to_string(help_value) elsif Ops.is(help_value, "list <string>") help = Builtins.mergestring( Convert.convert( help_value, from: "any", to: "list <string>" ), "\n" ) else Builtins.y2error( "Unsupported data type for 'help' key: %1, use 'string' or 'list<string>' type!", help_value ) end opts = [] Builtins.foreach(Ops.get(mappings, action, [])) do |option| optn = { "name" => option, "help" => Ops.get_string(, [option, "help"], "") } # add type specification if it's present if Ops.get_string(, [option, "type"], "") != "" optn = Builtins.add( optn, "type", Ops.get_string(, [option, "type"], "") ) end opts = Builtins.add(opts, optn) end actiondescr = { "help" => help, "name" => action, "options" => opts } # add example if it's present if Builtins.haskey(Ops.get(actions, action, {}), "example") example = Ops.get(actions, [action, "example"]) examples = Array(example) actiondescr = Builtins.add(actiondescr, "examples", examples) end commands = Builtins.add(commands, actiondescr) end Ops.set(exportmap, "commands", commands) Ops.set(exportmap, "module", Ops.get_string(@cmdlinespec, "id", "")) begin XML.YCPToXMLFile(:xmlhelp, exportmap, xmlfilename) rescue XMLSerializationError => e # error message - creation of xml failed Print( _("Failed to create XML file.") ) Builtins.y2error("Failed to serialize xml help: #{e.inspect}") return false end Builtins.y2milestone("exported XML map: %1", exportmap) return true end false end |