Skip to content

Commit

Permalink
Merge pull request #19 from ysim/v0.1.1
Browse files Browse the repository at this point in the history
v0.1.1
  • Loading branch information
ysim committed Jul 19, 2019
2 parents 185dca7 + 9f2e011 commit 0974116
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 52 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v0.1.1 (2019-07-19)

* Fixed bug that wouldn't allow the reading of a symlink specified by
$COOK_RECIPES_DIR (#14)
* Adjusted line spacing (#17)
* Show a prettier error message when a recipe file cannot be read (#18)
* Update blackfriday (1.5.1 -> 1.5.2), logrus (1.0.4 -> 1.4.2),
testify (1.2.1 -> 1.3.0), yaml.v2 (2.1.1 -> 2.2.2)

v0.1.0 (2017-06-19)

* Initial release on Homebrew
Expand Down
69 changes: 45 additions & 24 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@

[[constraint]]
name = "github.com/russross/blackfriday"
version = "1.5.1"
version = "1.5.2"

[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.4"
version = "1.4.2"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.1"
version = "1.3.0"

[[constraint]]
branch = "master"
name = "golang.org/x/net"
branch = "master"

[[constraint]]
name = "gopkg.in/yaml.v2"
version = "2.1.1"
version = "2.2.2"

[prune]
go-tests = true
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
version=v0.1.0
version=v0.1.1
binary_tarball="cook-$(version).tar.gz"
binary_location="${HOME}/bin/cook"
bash_completion_dir ?= "${HOME}/.bash_completion.d"

.PHONY: get-deps
get-deps:
go get github.com/sirupsen/logrus

.PHONY: build
build: main.go search.go validate.go parser.go
go build -ldflags "-X main.version=$(version)" -o cook main.go search.go validate.go parser.go
Expand Down
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ in the front matter, such as `tags: [vegetarian, spicy]` or
This program was inspired by Jason A. Donenfeld's
[pass](https://www.passwordstore.org/).

### Installation
## Installation

Homebrew:

Expand Down Expand Up @@ -68,9 +68,9 @@ Build from source:

1. Follow the above instructions for bash completion.

### Usage
## Usage

##### Create/port recipe files
### Create/port recipe files

In a directory at `$HOME/.recipes`, create some recipes files with the `.md`
(Markdown) extension, and with YAML front matter block. The file contents
Expand All @@ -95,16 +95,13 @@ should look something like this:

1. ...rest of the steps...

See the `recipes` subdirectory in this repo for some examples:
<https://github.com/ysim/recipes>

##### View a recipe
### View a recipe

cook [recipe name]

This will print the recipe to the screen with some light styling.

##### Validate the formatting of your recipe files
### Validate the formatting of your recipe files

cook validate

Expand All @@ -118,7 +115,7 @@ command to validate the formatting of your recipe files. This will walk through
You can also validate a single file. Bash completion is available for this
option.

##### Searching
### Searching

The following search syntaxes are supported:

Expand All @@ -135,13 +132,13 @@ Note that values with a space in them must either be quoted or escaped:
`cook search tags:'comfort food'`
`cook search tags:comfort\ food`

##### Edit a recipe
### Edit a recipe

cook edit [recipe name]

This will open the recipe in a text editor.

### Customizations
## Customizations

Here are a few environment variables that can be set to override the default
settings:
Expand Down
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ func GetBasenameWithoutExt(fullFilepath string) string {
func DisplayRecipe(fullFilepath string) {
recipeFile, err := ParseFile(fullFilepath)
if err != nil {
log.WithFields(log.Fields{
"file": fullFilepath,
}).Panic(err.Error())
fmt.Printf("Unable to read file: %s\n", fullFilepath)
os.Exit(1)
}
RenderMarkdown(recipeFile.Markdown)
}
Expand All @@ -154,6 +153,18 @@ func init() {
if prefix == "" {
prefix = fmt.Sprintf("%s/.recipes", homeDir)
}
fileInfo, err := os.Lstat(prefix)
if err != nil {
fmt.Printf("There was an error getting file info for: %s\n", prefix)
os.Exit(1)
}
if fileInfo.Mode()&os.ModeSymlink != 0 {
prefix, err = os.Readlink(prefix)
if err != nil {
fmt.Printf("Unable to read symlink: %s\n", prefix)
os.Exit(1)
}
}
suffix = os.Getenv("COOK_RECIPES_EXT")
if suffix == "" {
suffix = ".md"
Expand Down
9 changes: 5 additions & 4 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
style_h1 = "\n\n\x1b[1;4;92m" // green, bold, underline, high intensity
style_h1 = "\n\x1b[1;4;92m" // green, bold, underline, high intensity
style_h2 = "\n\n\x1b[4;92m" // green, underline, high intensity
style_h3 = "\n\n\x1b[1;92m" // green, bold, high intensity
style_h4 = "\n\n\x1b[1;93m" // yellow, bold, high intensity
Expand All @@ -32,6 +32,8 @@ func ParseHTML(htmlBytes []byte) ([]string, error) {
token := z.Next()
switch token {
case html.ErrorToken:
// Add trailing newline to make space before next command prompt
output = append(output, "\n")
return output, z.Err()
case html.TextToken:
text := string(z.Text())
Expand Down Expand Up @@ -60,7 +62,7 @@ func ParseHTML(htmlBytes []byte) ([]string, error) {
output = append(output, style_em)
case "p":
if !inListItem {
output = append(output, "\n\n")
output = append(output, "\n")
}
case "li":
inListItem = true
Expand All @@ -71,14 +73,13 @@ func ParseHTML(htmlBytes []byte) ([]string, error) {
}
switch isOrderedList {
case true:
output = append(output, fmt.Sprintf("%d. ", listPosition))
output = append(output, fmt.Sprintf("\n%d. ", listPosition))
case false:
output = append(output, "- ")
}
case "ol":
isOrderedList = true
listPosition = 0
output = append(output, "\n")
depth++
case "ul":
depth++
Expand Down

0 comments on commit 0974116

Please sign in to comment.