mirror of
				https://github.com/cheat/cheat.git
				synced 2025-11-04 07:45:28 +01:00 
			
		
		
		
	@@ -3,6 +3,7 @@ package main
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"regexp"
 | 
			
		||||
	"sort"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"text/tabwriter"
 | 
			
		||||
@@ -45,6 +46,39 @@ func cmdList(opts map[string]interface{}, conf config.Config) {
 | 
			
		||||
		return flattened[i].Title < flattened[j].Title
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	// filter if <cheatsheet> was specified
 | 
			
		||||
	// NB: our docopt specification is misleading here. When used in conjunction
 | 
			
		||||
	// with `-l`, `<cheatsheet>` is really a pattern against which to filter
 | 
			
		||||
	// sheet titles.
 | 
			
		||||
	if opts["<cheatsheet>"] != nil {
 | 
			
		||||
 | 
			
		||||
		// initialize a slice of filtered sheets
 | 
			
		||||
		filtered := []sheet.Sheet{}
 | 
			
		||||
 | 
			
		||||
		// initialize our filter pattern
 | 
			
		||||
		pattern := "(?i)" + opts["<cheatsheet>"].(string)
 | 
			
		||||
 | 
			
		||||
		// compile the regex
 | 
			
		||||
		reg, err := regexp.Compile(pattern)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Fprintln(
 | 
			
		||||
				os.Stderr,
 | 
			
		||||
				fmt.Sprintf("failed to compile regexp: %s, %v", pattern, err),
 | 
			
		||||
			)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// iterate over each cheatsheet, and pass-through those which match the
 | 
			
		||||
		// filter pattern
 | 
			
		||||
		for _, s := range flattened {
 | 
			
		||||
			if reg.MatchString(s.Title) {
 | 
			
		||||
				filtered = append(filtered, s)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		flattened = filtered
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// exit early if no cheatsheets are available
 | 
			
		||||
	if len(flattened) == 0 {
 | 
			
		||||
		os.Exit(0)
 | 
			
		||||
 
 | 
			
		||||
@@ -35,6 +35,9 @@ Examples:
 | 
			
		||||
  To list all available cheatsheets:
 | 
			
		||||
    cheat -l
 | 
			
		||||
 | 
			
		||||
  To list all cheatsheets whose titles match "apt":
 | 
			
		||||
    cheat -l apt
 | 
			
		||||
 | 
			
		||||
  To list all tags in use:
 | 
			
		||||
    cheat -T
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ import (
 | 
			
		||||
	"github.com/cheat/cheat/internal/config"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const version = "3.1.1"
 | 
			
		||||
const version = "3.2.0"
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -44,6 +44,9 @@ Examples:
 | 
			
		||||
  To list all available cheatsheets:
 | 
			
		||||
    cheat -l
 | 
			
		||||
 | 
			
		||||
  To list all cheatsheets whose titles match "apt":
 | 
			
		||||
    cheat -l apt
 | 
			
		||||
 | 
			
		||||
  To list all tags in use:
 | 
			
		||||
    cheat -T
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							@@ -60,7 +60,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
 | 
			
		||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
			
		||||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU=
 | 
			
		||||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
 | 
			
		||||
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
 | 
			
		||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
			
		||||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
 | 
			
		||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								vendor/gopkg.in/yaml.v2/.travis.yml
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								vendor/gopkg.in/yaml.v2/.travis.yml
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,12 +1,16 @@
 | 
			
		||||
language: go
 | 
			
		||||
 | 
			
		||||
go:
 | 
			
		||||
    - 1.4
 | 
			
		||||
    - 1.5
 | 
			
		||||
    - 1.6
 | 
			
		||||
    - 1.7
 | 
			
		||||
    - 1.8
 | 
			
		||||
    - 1.9
 | 
			
		||||
    - tip
 | 
			
		||||
    - "1.4.x"
 | 
			
		||||
    - "1.5.x"
 | 
			
		||||
    - "1.6.x"
 | 
			
		||||
    - "1.7.x"
 | 
			
		||||
    - "1.8.x"
 | 
			
		||||
    - "1.9.x"
 | 
			
		||||
    - "1.10.x"
 | 
			
		||||
    - "1.11.x"
 | 
			
		||||
    - "1.12.x"
 | 
			
		||||
    - "1.13.x"
 | 
			
		||||
    - "tip"
 | 
			
		||||
 | 
			
		||||
go_import_path: gopkg.in/yaml.v2
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										78
									
								
								vendor/gopkg.in/yaml.v2/scannerc.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										78
									
								
								vendor/gopkg.in/yaml.v2/scannerc.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -634,13 +634,14 @@ func yaml_parser_fetch_more_tokens(parser *yaml_parser_t) bool {
 | 
			
		||||
			need_more_tokens = true
 | 
			
		||||
		} else {
 | 
			
		||||
			// Check if any potential simple key may occupy the head position.
 | 
			
		||||
			if !yaml_parser_stale_simple_keys(parser) {
 | 
			
		||||
				return false
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			for i := range parser.simple_keys {
 | 
			
		||||
			for i := len(parser.simple_keys) - 1; i >= 0; i-- {
 | 
			
		||||
				simple_key := &parser.simple_keys[i]
 | 
			
		||||
				if simple_key.possible && simple_key.token_number == parser.tokens_parsed {
 | 
			
		||||
				if simple_key.token_number < parser.tokens_parsed {
 | 
			
		||||
					break
 | 
			
		||||
				}
 | 
			
		||||
				if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok {
 | 
			
		||||
					return false
 | 
			
		||||
				} else if valid && simple_key.token_number == parser.tokens_parsed {
 | 
			
		||||
					need_more_tokens = true
 | 
			
		||||
					break
 | 
			
		||||
				}
 | 
			
		||||
@@ -678,11 +679,6 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Remove obsolete potential simple keys.
 | 
			
		||||
	if !yaml_parser_stale_simple_keys(parser) {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Check the indentation level against the current column.
 | 
			
		||||
	if !yaml_parser_unroll_indent(parser, parser.mark.column) {
 | 
			
		||||
		return false
 | 
			
		||||
@@ -837,29 +833,30 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool {
 | 
			
		||||
		"found character that cannot start any token")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Check the list of potential simple keys and remove the positions that
 | 
			
		||||
// cannot contain simple keys anymore.
 | 
			
		||||
func yaml_parser_stale_simple_keys(parser *yaml_parser_t) bool {
 | 
			
		||||
	// Check for a potential simple key for each flow level.
 | 
			
		||||
	for i := range parser.simple_keys {
 | 
			
		||||
		simple_key := &parser.simple_keys[i]
 | 
			
		||||
 | 
			
		||||
		// The specification requires that a simple key
 | 
			
		||||
		//
 | 
			
		||||
		//  - is limited to a single line,
 | 
			
		||||
		//  - is shorter than 1024 characters.
 | 
			
		||||
		if simple_key.possible && (simple_key.mark.line < parser.mark.line || simple_key.mark.index+1024 < parser.mark.index) {
 | 
			
		||||
 | 
			
		||||
			// Check if the potential simple key to be removed is required.
 | 
			
		||||
			if simple_key.required {
 | 
			
		||||
				return yaml_parser_set_scanner_error(parser,
 | 
			
		||||
					"while scanning a simple key", simple_key.mark,
 | 
			
		||||
					"could not find expected ':'")
 | 
			
		||||
			}
 | 
			
		||||
			simple_key.possible = false
 | 
			
		||||
		}
 | 
			
		||||
func yaml_simple_key_is_valid(parser *yaml_parser_t, simple_key *yaml_simple_key_t) (valid, ok bool) {
 | 
			
		||||
	if !simple_key.possible {
 | 
			
		||||
		return false, true
 | 
			
		||||
	}
 | 
			
		||||
	return true
 | 
			
		||||
 | 
			
		||||
	// The 1.2 specification says:
 | 
			
		||||
	//
 | 
			
		||||
	//     "If the ? indicator is omitted, parsing needs to see past the
 | 
			
		||||
	//     implicit key to recognize it as such. To limit the amount of
 | 
			
		||||
	//     lookahead required, the “:” indicator must appear at most 1024
 | 
			
		||||
	//     Unicode characters beyond the start of the key. In addition, the key
 | 
			
		||||
	//     is restricted to a single line."
 | 
			
		||||
	//
 | 
			
		||||
	if simple_key.mark.line < parser.mark.line || simple_key.mark.index+1024 < parser.mark.index {
 | 
			
		||||
		// Check if the potential simple key to be removed is required.
 | 
			
		||||
		if simple_key.required {
 | 
			
		||||
			return false, yaml_parser_set_scanner_error(parser,
 | 
			
		||||
				"while scanning a simple key", simple_key.mark,
 | 
			
		||||
				"could not find expected ':'")
 | 
			
		||||
		}
 | 
			
		||||
		simple_key.possible = false
 | 
			
		||||
		return false, true
 | 
			
		||||
	}
 | 
			
		||||
	return true, true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Check if a simple key may start at the current position and add it if
 | 
			
		||||
@@ -879,8 +876,8 @@ func yaml_parser_save_simple_key(parser *yaml_parser_t) bool {
 | 
			
		||||
			possible:     true,
 | 
			
		||||
			required:     required,
 | 
			
		||||
			token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head),
 | 
			
		||||
			mark:         parser.mark,
 | 
			
		||||
		}
 | 
			
		||||
		simple_key.mark = parser.mark
 | 
			
		||||
 | 
			
		||||
		if !yaml_parser_remove_simple_key(parser) {
 | 
			
		||||
			return false
 | 
			
		||||
@@ -912,7 +909,12 @@ const max_flow_level = 10000
 | 
			
		||||
// Increase the flow level and resize the simple key list if needed.
 | 
			
		||||
func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool {
 | 
			
		||||
	// Reset the simple key on the next level.
 | 
			
		||||
	parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{})
 | 
			
		||||
	parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{
 | 
			
		||||
		possible:     false,
 | 
			
		||||
		required:     false,
 | 
			
		||||
		token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head),
 | 
			
		||||
		mark:         parser.mark,
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	// Increase the flow level.
 | 
			
		||||
	parser.flow_level++
 | 
			
		||||
@@ -1286,7 +1288,11 @@ func yaml_parser_fetch_value(parser *yaml_parser_t) bool {
 | 
			
		||||
	simple_key := &parser.simple_keys[len(parser.simple_keys)-1]
 | 
			
		||||
 | 
			
		||||
	// Have we found a simple key?
 | 
			
		||||
	if simple_key.possible {
 | 
			
		||||
	if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok {
 | 
			
		||||
		return false
 | 
			
		||||
 | 
			
		||||
	} else if valid {
 | 
			
		||||
 | 
			
		||||
		// Create the KEY token and insert it into the queue.
 | 
			
		||||
		token := yaml_token_t{
 | 
			
		||||
			typ:        yaml_KEY_TOKEN,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/gopkg.in/yaml.v2/yaml.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/gopkg.in/yaml.v2/yaml.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -89,7 +89,7 @@ func UnmarshalStrict(in []byte, out interface{}) (err error) {
 | 
			
		||||
	return unmarshal(in, out, true)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// A Decorder reads and decodes YAML values from an input stream.
 | 
			
		||||
// A Decoder reads and decodes YAML values from an input stream.
 | 
			
		||||
type Decoder struct {
 | 
			
		||||
	strict bool
 | 
			
		||||
	parser *parser
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							@@ -53,5 +53,5 @@ github.com/mitchellh/go-homedir
 | 
			
		||||
golang.org/x/sys/unix
 | 
			
		||||
# gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0
 | 
			
		||||
gopkg.in/yaml.v1
 | 
			
		||||
# gopkg.in/yaml.v2 v2.2.5
 | 
			
		||||
# gopkg.in/yaml.v2 v2.2.7
 | 
			
		||||
gopkg.in/yaml.v2
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user