vendor/github.com/spf13/cobra/cobra.go
changeset 265 05c40b36d3b2
parent 256 6d9efbef00a9
equal deleted inserted replaced
264:8f478162d991 265:05c40b36d3b2
     1 // Copyright © 2013 Steve Francia <spf@spf13.com>.
     1 // Copyright 2013-2022 The Cobra Authors
     2 //
     2 //
     3 // Licensed under the Apache License, Version 2.0 (the "License");
     3 // Licensed under the Apache License, Version 2.0 (the "License");
     4 // you may not use this file except in compliance with 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
     5 // You may obtain a copy of the License at
     6 // http://www.apache.org/licenses/LICENSE-2.0
     6 //
       
     7 //      http://www.apache.org/licenses/LICENSE-2.0
     7 //
     8 //
     8 // Unless required by applicable law or agreed to in writing, software
     9 // Unless required by applicable law or agreed to in writing, software
     9 // distributed under the License is distributed on an "AS IS" BASIS,
    10 // distributed under the License is distributed on an "AS IS" BASIS,
    10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11 // See the License for the specific language governing permissions and
    12 // See the License for the specific language governing permissions and
    37 	"gt":                      Gt,
    38 	"gt":                      Gt,
    38 	"eq":                      Eq,
    39 	"eq":                      Eq,
    39 }
    40 }
    40 
    41 
    41 var initializers []func()
    42 var initializers []func()
       
    43 var finalizers []func()
       
    44 
       
    45 const (
       
    46 	defaultPrefixMatching  = false
       
    47 	defaultCommandSorting  = true
       
    48 	defaultCaseInsensitive = false
       
    49 )
    42 
    50 
    43 // EnablePrefixMatching allows to set automatic prefix matching. Automatic prefix matching can be a dangerous thing
    51 // EnablePrefixMatching allows to set automatic prefix matching. Automatic prefix matching can be a dangerous thing
    44 // to automatically enable in CLI tools.
    52 // to automatically enable in CLI tools.
    45 // Set this to true to enable it.
    53 // Set this to true to enable it.
    46 var EnablePrefixMatching = false
    54 var EnablePrefixMatching = defaultPrefixMatching
    47 
    55 
    48 // EnableCommandSorting controls sorting of the slice of commands, which is turned on by default.
    56 // EnableCommandSorting controls sorting of the slice of commands, which is turned on by default.
    49 // To disable sorting, set it to false.
    57 // To disable sorting, set it to false.
    50 var EnableCommandSorting = true
    58 var EnableCommandSorting = defaultCommandSorting
       
    59 
       
    60 // EnableCaseInsensitive allows case-insensitive commands names. (case sensitive by default)
       
    61 var EnableCaseInsensitive = defaultCaseInsensitive
    51 
    62 
    52 // MousetrapHelpText enables an information splash screen on Windows
    63 // MousetrapHelpText enables an information splash screen on Windows
    53 // if the CLI is started from explorer.exe.
    64 // if the CLI is started from explorer.exe.
    54 // To disable the mousetrap, just set this variable to blank string ("").
    65 // To disable the mousetrap, just set this variable to blank string ("").
    55 // Works only on Microsoft Windows.
    66 // Works only on Microsoft Windows.
    80 
    91 
    81 // OnInitialize sets the passed functions to be run when each command's
    92 // OnInitialize sets the passed functions to be run when each command's
    82 // Execute method is called.
    93 // Execute method is called.
    83 func OnInitialize(y ...func()) {
    94 func OnInitialize(y ...func()) {
    84 	initializers = append(initializers, y...)
    95 	initializers = append(initializers, y...)
       
    96 }
       
    97 
       
    98 // OnFinalize sets the passed functions to be run when each command's
       
    99 // Execute method is terminated.
       
   100 func OnFinalize(y ...func()) {
       
   101 	finalizers = append(finalizers, y...)
    85 }
   102 }
    86 
   103 
    87 // FIXME Gt is unused by cobra and should be removed in a version 2. It exists only for compatibility with users of cobra.
   104 // FIXME Gt is unused by cobra and should be removed in a version 2. It exists only for compatibility with users of cobra.
    88 
   105 
    89 // Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans,
   106 // Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans,