doc_util.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2015 Red Hat Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. package cobra
  14. // Test to see if we have a reason to print See Also information in docs
  15. // Basically this is a test for a parent commend or a subcommand which is
  16. // both not deprecated and not the autogenerated help command.
  17. func (cmd *Command) hasSeeAlso() bool {
  18. if cmd.HasParent() {
  19. return true
  20. }
  21. children := cmd.Commands()
  22. if len(children) == 0 {
  23. return false
  24. }
  25. for _, c := range children {
  26. if !c.IsAvailableCommand() || c == cmd.helpCommand {
  27. continue
  28. }
  29. return true
  30. }
  31. return false
  32. }