Method: Yast::CommandLineClass#PrintGeneralHelp

Defined in:
library/commandline/src/modules/CommandLine.rb

#PrintGeneralHelpObject

Print a general help - list of available command.



723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
# File 'library/commandline/src/modules/CommandLine.rb', line 723

def PrintGeneralHelp
  # display custom defined help instead of generic one
  if Builtins.haskey(@modulecommands, "customhelp")
    Print(Ops.get_string(@modulecommands, "customhelp", ""))
    return
  end

  # translators: default module description if none is provided by the module itself
  Print(
    Ops.add(
      Ops.get_locale(@modulecommands, "help", _("This is a YaST module.")),
      "\n"
    )
  )
  # translators: short help title for command line
  Print(_("Basic Syntax:"))

  if @interactive
    # translators: module command line help
    # translate <command> and [options] only!
    Print(_("    <command> [options]"))
    # translators: module command line help
    # translate <command> only!
    Print(_("    <command> help"))
    # translators: module command line help
    Print("    help")
    Print("    longhelp")
    Print("    xmlhelp")
    Print("")
    Print("    exit")
    Print("    abort")
  else
    # translators: module command line help, %1 is the module name
    Print(
      Builtins.sformat(
        "    yast2 %1 interactive",
        Ops.get_string(@modulecommands, "id", "")
      )
    )

    # translators: module command line help, %1 is the module name
    # translate <command> and [options] only!
    Print(
      Builtins.sformat(
        _("    yast2 %1 <command> [verbose] [options]"),
        Ops.get_string(@modulecommands, "id", "")
      )
    )
    # translators: module command line help, %1 is the module name
    Print(
      Builtins.sformat(
        "    yast2 %1 help",
        Ops.get_string(@modulecommands, "id", "")
      )
    )
    Print(
      Builtins.sformat(
        "    yast2 %1 longhelp",
        Ops.get_string(@modulecommands, "id", "")
      )
    )
    Print(
      Builtins.sformat(
        "    yast2 %1 xmlhelp",
        Ops.get_string(@modulecommands, "id", "")
      )
    )
    # translators: module command line help, %1 is the module name
    # translate <command> only!
    Print(
      Builtins.sformat(
        _("    yast2 %1 <command> help"),
        Ops.get_string(@modulecommands, "id", "")
      )
    )
  end

  Print("")
  # translators: command line title: list of available commands
  Print(_("Commands:"))

  longest = 0
  Builtins.foreach(Ops.get_map(@modulecommands, "actions", {})) do |action, _desc|
    longest = Builtins.size(action) if Ops.greater_than(Builtins.size(action), longest)
  end

  Builtins.maplist(Ops.get_map(@modulecommands, "actions", {})) do |cmd, desc|
    if !Builtins.haskey(desc, "help")
      # translators: error message: module does not provide any help messages
      Print(
        Builtins.sformat(
          "    %1  %2",
          String.Pad(cmd, longest),
          _("No help available.")
        )
      )
    end
    if Ops.is_string?(Ops.get(desc, "help"))
      Print(
        Builtins.sformat(
          "    %1  %2",
          String.Pad(cmd, longest),
          Ops.get_string(desc, "help", "")
        )
      )
    # multiline help text
    elsif Ops.is(Ops.get(desc, "help"), "list <string>")
      help = Ops.get_list(desc, "help", [])

      if Ops.greater_than(Builtins.size(help), 0)
        Print(
          Builtins.sformat(
            "    %1  %2",
            String.Pad(cmd, longest),
            Ops.get(help, 0, "")
          )
        )
        help = Builtins.remove(help, 0)
      end

      Builtins.foreach(help) do |h|
        Print(Builtins.sformat("    %1  %2", String.Pad("", longest), h))
      end
    else
      # fallback message - invalid help has been provided by the yast module
      Print(
        Builtins.sformat(
          "    %1  %2",
          String.Pad(cmd, longest),
          _("<Error: invalid help>")
        )
      )
    end
  end
  Print("")
  if !@interactive
    # translators: module command line help, %1 is the module name
    Print(
      Builtins.sformat(
        _("Run 'yast2 %1 <command> help' for a list of available options."),
        Ops.get_string(@modulecommands, "id", "")
      )
    )
    Print("")
  end

  nil
end