Documentation ¶
Index ¶
- Variables
- func GetCobraHelpUsageFuncs(hs *HelpSystem) (HelpFunc, UsageFunc)
- func GetCobraHelpUsageTemplates(hs *HelpSystem) (string, string)
- func NewCobraHelpCommand(hs *HelpSystem) *cobra.Command
- func RenderToMarkdown(t *template.Template, data interface{}, output *os.File) (string, error)
- type HelpError
- type HelpFunc
- type HelpPage
- type HelpSystem
- func (hs *HelpSystem) AddSection(section *Section)
- func (hs *HelpSystem) ComputeRenderData(userQuery *SectionQuery) (map[string]interface{}, bool)
- func (hs *HelpSystem) GetSectionWithSlug(slug string) (*Section, error)
- func (hs *HelpSystem) GetTopLevelHelpPage() *HelpPage
- func (hs *HelpSystem) LoadSectionsFromFS(f fs.FS, dir string) error
- func (hs *HelpSystem) RenderTopicHelp(topicSection *Section, options *RenderOptions) (string, error)
- func (hs *HelpSystem) SetupCobraRootCommand(cmd *cobra.Command)
- type RenderOptions
- type Section
- func (s *Section) DefaultApplications() []*Section
- func (s *Section) DefaultExamples() []*Section
- func (s *Section) DefaultGeneralTopic() []*Section
- func (s *Section) DefaultTutorials() []*Section
- func (s *Section) IsForCommand(command string) bool
- func (s *Section) IsForFlag(flag string) bool
- func (s *Section) IsForTopic(topic string) bool
- func (s *Section) OtherApplications() []*Section
- func (s *Section) OtherExamples() []*Section
- func (s *Section) OtherTutorials() []*Section
- type SectionQuery
- func (s *SectionQuery) Clone() *SectionQuery
- func (s *SectionQuery) DontReturnApplications() *SectionQuery
- func (s *SectionQuery) DontReturnExamples() *SectionQuery
- func (s *SectionQuery) DontReturnTopics() *SectionQuery
- func (s *SectionQuery) DontReturnTutorials() *SectionQuery
- func (s *SectionQuery) FilterSections(sections ...*Section) *SectionQuery
- func (s *SectionQuery) FindSections(sections []*Section) []*Section
- func (s *SectionQuery) GetOnlyQueryAsString() string
- func (s *SectionQuery) GetRequestedTypesAsString() string
- func (s *SectionQuery) HasOnlyQueries() bool
- func (s *SectionQuery) HasRestrictedReturnTypes() bool
- func (s *SectionQuery) IsOnlyTopLevel() bool
- func (s *SectionQuery) ResetOnlyQueries() *SectionQuery
- func (s *SectionQuery) ReturnAllTypes() *SectionQuery
- func (s *SectionQuery) ReturnAnyOfCommands(commands ...string) *SectionQuery
- func (s *SectionQuery) ReturnAnyOfFlags(flags ...string) *SectionQuery
- func (s *SectionQuery) ReturnAnyOfSlugs(slugs ...string) *SectionQuery
- func (s *SectionQuery) ReturnAnyOfTopics(topics ...string) *SectionQuery
- func (s *SectionQuery) ReturnApplications() *SectionQuery
- func (s *SectionQuery) ReturnExamples() *SectionQuery
- func (s *SectionQuery) ReturnOnlyCommands(commands ...string) *SectionQuery
- func (s *SectionQuery) ReturnOnlyFlags(flags ...string) *SectionQuery
- func (s *SectionQuery) ReturnOnlyNotShownByDefault() *SectionQuery
- func (s *SectionQuery) ReturnOnlyShownByDefault() *SectionQuery
- func (s *SectionQuery) ReturnOnlyTopLevel() *SectionQuery
- func (s *SectionQuery) ReturnOnlyTopics(topics ...string) *SectionQuery
- func (s *SectionQuery) ReturnTopics() *SectionQuery
- func (s *SectionQuery) ReturnTutorials() *SectionQuery
- func (s *SectionQuery) SearchForCommand(command string) *SectionQuery
- func (s *SectionQuery) SearchForSlug(slug string) *SectionQuery
- type SectionType
- type UsageFunc
Constants ¶
This section is empty.
Variables ¶
var COBRA_COMMAND_HELP_TEMPLATE string
var COBRA_COMMAND_SHORT_HELP_TEMPLATE string
var COBRA_COMMAND_USAGE_TEMPLATE string
COBRA_COMMAND_USAGE_TEMPLATE - template used by the glazed library help cobra command. This template has been adapted from the cobra usage command template.
Original: https://github.com/spf13/cobra
Copyright 2013-2022 The Cobra Authors ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
2022-12-03 - Manuel Odendahl - Augmented template with sections 2022-12-04 - Manuel Odendahl - Significantly reworked to support markdown sections
var HELP_LIST_TEMPLATE string
var HELP_LONG_SECTION_TEMPLATE string
var HELP_SHORT_SECTION_TEMPLATE string
var HELP_SHORT_TOPIC_TEMPLATE string
var HELP_TOPIC_TEMPLATE string
Functions ¶
func GetCobraHelpUsageFuncs ¶
func GetCobraHelpUsageFuncs(hs *HelpSystem) (HelpFunc, UsageFunc)
func GetCobraHelpUsageTemplates ¶
func GetCobraHelpUsageTemplates(hs *HelpSystem) (string, string)
func NewCobraHelpCommand ¶
func NewCobraHelpCommand(hs *HelpSystem) *cobra.Command
NewCobraHelpCommand uses the InitDefaultHelpCommand code from cobra. This code is lifted from cobra and modified to accommodate help sections
Copyright 2013-2022 The Cobra Authors ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
2022-12-03 - Manuel Odendahl - Added support for help sections 2022-12-04 - Manuel Odendahl - Significantly reworked to support markdown sections
Types ¶
type HelpPage ¶
type HelpPage struct { DefaultGeneralTopics []*Section OtherGeneralTopics []*Section // this is just the concatenation of default and others AllGeneralTopics []*Section DefaultExamples []*Section OtherExamples []*Section AllExamples []*Section DefaultApplications []*Section OtherApplications []*Section AllApplications []*Section DefaultTutorials []*Section OtherTutorials []*Section AllTutorials []*Section }
HelpPage contains all the sections related to a command
func NewHelpPage ¶
type HelpSystem ¶
type HelpSystem struct {
Sections []*Section
}
func NewHelpSystem ¶
func NewHelpSystem() *HelpSystem
func (*HelpSystem) AddSection ¶
func (hs *HelpSystem) AddSection(section *Section)
func (*HelpSystem) ComputeRenderData ¶
func (hs *HelpSystem) ComputeRenderData(userQuery *SectionQuery) (map[string]interface{}, bool)
func (*HelpSystem) GetSectionWithSlug ¶
func (hs *HelpSystem) GetSectionWithSlug(slug string) (*Section, error)
func (*HelpSystem) GetTopLevelHelpPage ¶
func (hs *HelpSystem) GetTopLevelHelpPage() *HelpPage
func (*HelpSystem) LoadSectionsFromFS ¶ added in v0.2.4
func (hs *HelpSystem) LoadSectionsFromFS(f fs.FS, dir string) error
func (*HelpSystem) RenderTopicHelp ¶
func (hs *HelpSystem) RenderTopicHelp( topicSection *Section, options *RenderOptions) (string, error)
func (*HelpSystem) SetupCobraRootCommand ¶ added in v0.2.46
func (hs *HelpSystem) SetupCobraRootCommand(cmd *cobra.Command)
type RenderOptions ¶
type RenderOptions struct { Query *SectionQuery ShowAllSections bool ShowShortTopic bool HelpCommand string ListSections bool }
type Section ¶
type Section struct { Slug string SectionType SectionType Title string SubTitle string Short string Content string // metadata used to search and select sections to be shown Topics []string Flags []string Commands []string // Show this section in the toplevel help IsTopLevel bool IsTemplate bool // show this template as a default example ShowPerDefault bool // Used to give some rough sense of order, not sure how useful this is going to be Order int HelpSystem *HelpSystem }
Section is a structure describing an actual documentation section.
This can describe:
- a general topic: think of this as an entry in a book
- an example: a way to run a certain command
- an application: a concrete use case for running a command. This can potentially use additional external tools, multiple commands, etc. While it is nice to keep these self-contained, it is not required.
- a tutorial: a step-by-step guide to running a command.
Run `glaze help help-system` for more information.
func LoadSectionFromMarkdown ¶
func (*Section) DefaultApplications ¶
func (*Section) DefaultExamples ¶
func (*Section) DefaultGeneralTopic ¶
func (*Section) DefaultTutorials ¶
func (*Section) IsForCommand ¶
func (*Section) IsForTopic ¶
func (*Section) OtherApplications ¶
func (*Section) OtherExamples ¶
func (*Section) OtherTutorials ¶
type SectionQuery ¶
type SectionQuery struct { OnlyShownByDefault bool OnlyNotShownByDefault bool OnlyTopLevel bool // only these types will be returned Types map[SectionType]bool // if any of these is set, and they match each of the Only types, // the section will be return Topics []string Flags []string Commands []string Slugs []string // this will return any section as long as it matches the Only strings All bool SearchedCommand string SearchedSlug string // a section will be returned only if it matches all // of the following criteria OnlyTopics []string OnlyFlags []string OnlyCommands []string // We often need to filter sections that have already been shown WithoutSections []*Section }
SectionQuery represents a query to get different types of sections.
This is used for example by the `help` command line function to render out the help sections for individual commands.
It can however also be used on its own.
func NewSectionQuery ¶
func NewSectionQuery() *SectionQuery
func (*SectionQuery) Clone ¶
func (s *SectionQuery) Clone() *SectionQuery
func (*SectionQuery) DontReturnApplications ¶
func (s *SectionQuery) DontReturnApplications() *SectionQuery
func (*SectionQuery) DontReturnExamples ¶
func (s *SectionQuery) DontReturnExamples() *SectionQuery
func (*SectionQuery) DontReturnTopics ¶
func (s *SectionQuery) DontReturnTopics() *SectionQuery
func (*SectionQuery) DontReturnTutorials ¶
func (s *SectionQuery) DontReturnTutorials() *SectionQuery
func (*SectionQuery) FilterSections ¶
func (s *SectionQuery) FilterSections(sections ...*Section) *SectionQuery
func (*SectionQuery) FindSections ¶
func (s *SectionQuery) FindSections(sections []*Section) []*Section
func (*SectionQuery) GetOnlyQueryAsString ¶
func (s *SectionQuery) GetOnlyQueryAsString() string
func (*SectionQuery) GetRequestedTypesAsString ¶
func (s *SectionQuery) GetRequestedTypesAsString() string
func (*SectionQuery) HasOnlyQueries ¶
func (s *SectionQuery) HasOnlyQueries() bool
func (*SectionQuery) HasRestrictedReturnTypes ¶
func (s *SectionQuery) HasRestrictedReturnTypes() bool
func (*SectionQuery) IsOnlyTopLevel ¶
func (s *SectionQuery) IsOnlyTopLevel() bool
func (*SectionQuery) ResetOnlyQueries ¶
func (s *SectionQuery) ResetOnlyQueries() *SectionQuery
func (*SectionQuery) ReturnAllTypes ¶
func (s *SectionQuery) ReturnAllTypes() *SectionQuery
func (*SectionQuery) ReturnAnyOfCommands ¶
func (s *SectionQuery) ReturnAnyOfCommands(commands ...string) *SectionQuery
func (*SectionQuery) ReturnAnyOfFlags ¶
func (s *SectionQuery) ReturnAnyOfFlags(flags ...string) *SectionQuery
func (*SectionQuery) ReturnAnyOfSlugs ¶
func (s *SectionQuery) ReturnAnyOfSlugs(slugs ...string) *SectionQuery
func (*SectionQuery) ReturnAnyOfTopics ¶
func (s *SectionQuery) ReturnAnyOfTopics(topics ...string) *SectionQuery
func (*SectionQuery) ReturnApplications ¶
func (s *SectionQuery) ReturnApplications() *SectionQuery
func (*SectionQuery) ReturnExamples ¶
func (s *SectionQuery) ReturnExamples() *SectionQuery
func (*SectionQuery) ReturnOnlyCommands ¶
func (s *SectionQuery) ReturnOnlyCommands(commands ...string) *SectionQuery
func (*SectionQuery) ReturnOnlyFlags ¶
func (s *SectionQuery) ReturnOnlyFlags(flags ...string) *SectionQuery
func (*SectionQuery) ReturnOnlyNotShownByDefault ¶
func (s *SectionQuery) ReturnOnlyNotShownByDefault() *SectionQuery
func (*SectionQuery) ReturnOnlyShownByDefault ¶
func (s *SectionQuery) ReturnOnlyShownByDefault() *SectionQuery
func (*SectionQuery) ReturnOnlyTopLevel ¶
func (s *SectionQuery) ReturnOnlyTopLevel() *SectionQuery
func (*SectionQuery) ReturnOnlyTopics ¶
func (s *SectionQuery) ReturnOnlyTopics(topics ...string) *SectionQuery
func (*SectionQuery) ReturnTopics ¶
func (s *SectionQuery) ReturnTopics() *SectionQuery
func (*SectionQuery) ReturnTutorials ¶
func (s *SectionQuery) ReturnTutorials() *SectionQuery
func (*SectionQuery) SearchForCommand ¶
func (s *SectionQuery) SearchForCommand(command string) *SectionQuery
func (*SectionQuery) SearchForSlug ¶
func (s *SectionQuery) SearchForSlug(slug string) *SectionQuery
type SectionType ¶
type SectionType int
const ( SectionGeneralTopic SectionType = iota SectionExample SectionApplication SectionTutorial )
func SectionTypeFromString ¶
func SectionTypeFromString(s string) (SectionType, error)
func (SectionType) String ¶
func (s SectionType) String() string