Package userinput provides functions to obtain interactive user input for command line tools.



    View Source
    const SupportedLabels = "pool, powerunit_hostname, powerunit_outlet"

      SupportedLabels lists all supported labels for batch-update-duts.


      This section is empty.


      func DropCommentLines

      func DropCommentLines(text string) string

        DropCommentLines drops lines from text that are comment lines, commented using commentLines().

        func GetDeviceSpecs

        func GetDeviceSpecs(initial *inventory.DeviceUnderTest, helpText string, promptFunc PromptFunc, validateFunc SpecsValidationFunc) (*inventory.DeviceUnderTest, error)

          GetDeviceSpecs interactively obtains inventory.DeviceUnderTest from the user.

          This function provides the user with initial specs, some help text and an example of a complete device spec. User's updated specs are parsed and any errors are reported back to the user, allowing the user to fix the errors. promptFunc is used to prompt the user on parsing errors, to give them a choice to continue or abort the input session.

          Callers may pass a non-nil validateFunc to validate the user's updated specs. validateFunc is called within the userinput iteration loop described above, and errors are reported back to error in the same way as parsing errors.

          This function returns upon successful parsing of the user input, or upon user initiated abort.

          func GetMCSVSpecs

          func GetMCSVSpecs(specsFile string) ([]*inventory.DeviceUnderTest, error)

            GetMCSVSpecs get a sequence of DeviceUnderTests in the MCSV format from the specified file.

            func GetRequestFromFiles

            func GetRequestFromFiles(fp string) (*fleet.BatchUpdateDutsRequest, error)

              GetRequestFromFiles form requests based on user's input file.

              func ValidBug

              func ValidBug(bug string) bool

                ValidBug returns true if the given bug string is acceptably formatted.


                type PromptFunc

                type PromptFunc func(string) bool

                  PromptFunc obtains consent from the user for the given request string.

                  This function is used to provide the user some context through the provided string and then obtain a yes/no answer from the user.

                  func CLIPrompt

                  func CLIPrompt(w io.Writer, r io.Reader, defaultResponse bool) PromptFunc

                    CLIPrompt returns a PromptFunc to prompt user on CLI.

                    In case of erroneous input from user, the returned PromptFunc prompts the user again. defaultResponse is returned on empty response from the user. In case of other system errors, the returned promptFunc returns false.

                    type SpecsValidationFunc

                    type SpecsValidationFunc func(*inventory.DeviceUnderTest) error

                      SpecsValidationFunc checks provided device specs for error.

                      This function returns nil if provided specs are valid.