mirror of
				https://github.com/cheat/cheat.git
				synced 2025-11-04 07:45:28 +01:00 
			
		
		
		
	feat: implement --all flag
				
					
				
			Implement an `--all` flag that can be used to view cheatsheets on all chaetpaths. (Resolves #548)
This commit is contained in:
		@@ -25,7 +25,7 @@ func TestCopyFlat(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// mock a cheatsheet struct
 | 
			
		||||
	sheet, err := New("foo", src.Name(), []string{}, false)
 | 
			
		||||
	sheet, err := New("foo", "community", src.Name(), []string{}, false)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("failed to init cheatsheet: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -72,7 +72,13 @@ func TestCopyDeep(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// mock a cheatsheet struct
 | 
			
		||||
	sheet, err := New("/cheat-tests/alpha/bravo/foo", src.Name(), []string{}, false)
 | 
			
		||||
	sheet, err := New(
 | 
			
		||||
		"/cheat-tests/alpha/bravo/foo",
 | 
			
		||||
		"community",
 | 
			
		||||
		src.Name(),
 | 
			
		||||
		[]string{},
 | 
			
		||||
		false,
 | 
			
		||||
	)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("failed to init cheatsheet: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,17 +10,19 @@ import (
 | 
			
		||||
 | 
			
		||||
// Sheet encapsulates sheet information
 | 
			
		||||
type Sheet struct {
 | 
			
		||||
	Title    string
 | 
			
		||||
	Path     string
 | 
			
		||||
	Text     string
 | 
			
		||||
	Tags     []string
 | 
			
		||||
	Syntax   string
 | 
			
		||||
	ReadOnly bool
 | 
			
		||||
	Title     string
 | 
			
		||||
	CheatPath string
 | 
			
		||||
	Path      string
 | 
			
		||||
	Text      string
 | 
			
		||||
	Tags      []string
 | 
			
		||||
	Syntax    string
 | 
			
		||||
	ReadOnly  bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// New initializes a new Sheet
 | 
			
		||||
func New(
 | 
			
		||||
	title string,
 | 
			
		||||
	cheatpath string,
 | 
			
		||||
	path string,
 | 
			
		||||
	tags []string,
 | 
			
		||||
	readOnly bool,
 | 
			
		||||
@@ -46,11 +48,12 @@ func New(
 | 
			
		||||
 | 
			
		||||
	// initialize and return a sheet
 | 
			
		||||
	return Sheet{
 | 
			
		||||
		Title:    title,
 | 
			
		||||
		Path:     path,
 | 
			
		||||
		Text:     text + "\n",
 | 
			
		||||
		Tags:     tags,
 | 
			
		||||
		Syntax:   fm.Syntax,
 | 
			
		||||
		ReadOnly: readOnly,
 | 
			
		||||
		Title:     title,
 | 
			
		||||
		CheatPath: cheatpath,
 | 
			
		||||
		Path:      path,
 | 
			
		||||
		Text:      text + "\n",
 | 
			
		||||
		Tags:      tags,
 | 
			
		||||
		Syntax:    fm.Syntax,
 | 
			
		||||
		ReadOnly:  readOnly,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,7 @@ func TestSheetSuccess(t *testing.T) {
 | 
			
		||||
	// initialize a sheet
 | 
			
		||||
	sheet, err := New(
 | 
			
		||||
		"foo",
 | 
			
		||||
		"community",
 | 
			
		||||
		mock.Path("sheet/foo"),
 | 
			
		||||
		[]string{"alpha", "bravo"},
 | 
			
		||||
		false,
 | 
			
		||||
@@ -61,6 +62,7 @@ func TestSheetFailure(t *testing.T) {
 | 
			
		||||
	// initialize a sheet
 | 
			
		||||
	_, err := New(
 | 
			
		||||
		"foo",
 | 
			
		||||
		"community",
 | 
			
		||||
		mock.Path("/does-not-exist"),
 | 
			
		||||
		[]string{"alpha", "bravo"},
 | 
			
		||||
		false,
 | 
			
		||||
@@ -77,6 +79,7 @@ func TestSheetFrontMatterFailure(t *testing.T) {
 | 
			
		||||
	// initialize a sheet
 | 
			
		||||
	_, err := New(
 | 
			
		||||
		"foo",
 | 
			
		||||
		"community",
 | 
			
		||||
		mock.Path("sheet/bad-fm"),
 | 
			
		||||
		[]string{"alpha", "bravo"},
 | 
			
		||||
		false,
 | 
			
		||||
 
 | 
			
		||||
@@ -59,7 +59,13 @@ func Load(cheatpaths []cp.Cheatpath) ([]map[string]sheet.Sheet, error) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// parse the cheatsheet file into a `sheet` struct
 | 
			
		||||
				s, err := sheet.New(title, path, cheatpath.Tags, cheatpath.ReadOnly)
 | 
			
		||||
				s, err := sheet.New(
 | 
			
		||||
					title,
 | 
			
		||||
					cheatpath.Name,
 | 
			
		||||
					path,
 | 
			
		||||
					cheatpath.Tags,
 | 
			
		||||
					cheatpath.ReadOnly,
 | 
			
		||||
				)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return fmt.Errorf(
 | 
			
		||||
						"failed to load sheet: %s, path: %s, err: %v",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user