Skip to content

Commit

Permalink
Merge pull request #18 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 0.5.0
  • Loading branch information
andyone authored May 26, 2017
2 parents 88cef30 + 8de600b commit 4be2160
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 48 deletions.
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Contributing Guidelines

Contributing guidelines for open-source EK projects.

**IMPORTANT! Contribute your code only if you have an excellent understanding of project idea and all existing code base. Otherwise, a nicely formatted issue will be more helpful to us.**

### Issues

1. Provide product version where the problem was found;
2. Provide info about your environment;
3. Provide detailed info about your problem;
4. Provide steps to reproduce the problem;
5. Provide actual and expected results.

### Code

1. Check your code **before** creating pull request;
2. If tests are present in a project, add tests for your code;
3. Add inline documentation for your code;
4. Apply code style used throughout the project;
5. Create your pull request to `develop` branch (_pull requests to other branches are not allowed_).
53 changes: 53 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
_Before opening an issue, search for similar bug reports or feature requests on GitHub Issues. If yes, please add a_ 👍 _reaction to the existing issue. If no similar issue can be found, fill out either the "Bug Report" or the "Feature Request" section below. Erase the other section and everything on and above this line._

### Bug report

**System info:**

* **Version used (`shdoc -v`):**
* **OS (`cat /etc/*-release`):**
* **Kernel (`uname -a`):**
* **Install tools:**

**System info:**

1. [First Step]
2. [Second Step]
3. [and so on...]

**Expected behavior:**

[What you expected to happen]

**Actual behavior:**

[What actually happened]

**Additional info:**

[Include gist of relevant config, logs, etc.]

Please run those if possible and link them from a [gist](http://gist.github.com).

---

### Feature Request

Opening a feature request kicks off a discussion. Requests may be closed if we're not actively planning to work on them.

**Proposal:**

[Description of the feature]

**Current behavior:**

[What currently happens]

**Desired behavior:**

[What you would like to happen]

**Use case:**

[Why is this important (helps with prioritizing requests)]

25 changes: 25 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### What did you implement:

Closes #XXXXX

### How did you implement it:

...

### How can we verify it:

...

### TODO's:

- [ ] Write tests
- [ ] Write documentation
- [ ] Check that there aren't other open pull requests for the same issue/feature
- [ ] Format your source code by `make fmt`
- [ ] Pass the test by `make test`
- [ ] Provide verification config / commands
- [ ] Enable "Allow edits from maintainers" for this PR
- [ ] Update the messages below

**Is this ready for review?:** No
**Is it a breaking change?:** No
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
########################################################################################

# This Makefile generated by GoMakeGen 0.5.0 using next command:
# This Makefile generated by GoMakeGen 0.6.0 using next command:
# gomakegen .

########################################################################################
Expand All @@ -16,7 +16,7 @@ shdoc:

deps:
git config --global http.https://pkg.re.followRedirects true
go get -d -v pkg.re/essentialkaos/ek.v8
go get -d -v pkg.re/essentialkaos/ek.v9

deps-test:
git config --global http.https://pkg.re.followRedirects true
Expand Down
26 changes: 26 additions & 0 deletions parser/fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build gofuzz

package parser

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2017 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"bytes"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func Fuzz(data []byte) int {
_, errs := readData("temp", bytes.NewReader(data))

if len(errs) != 0 {
return 0
}

return 1
}
23 changes: 14 additions & 9 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ package parser
import (
"bufio"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
"strings"

"pkg.re/essentialkaos/ek.v8/fsutil"
"pkg.re/essentialkaos/ek.v8/mathutil"
"pkg.re/essentialkaos/ek.v8/sliceutil"
"pkg.re/essentialkaos/ek.v8/strutil"
"pkg.re/essentialkaos/ek.v9/fsutil"
"pkg.re/essentialkaos/ek.v9/mathutil"
"pkg.re/essentialkaos/ek.v9/sliceutil"
"pkg.re/essentialkaos/ek.v9/strutil"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -306,7 +307,13 @@ func Parse(file string) (*Document, []error) {

defer fd.Close()

reader := bufio.NewReader(fd)
return readData(file, bufio.NewReader(fd))
}

// ////////////////////////////////////////////////////////////////////////////////// //

// readData read data
func readData(file string, reader io.Reader) (*Document, []error) {
scanner := bufio.NewScanner(reader)

var buffer []string
Expand Down Expand Up @@ -411,8 +418,6 @@ func Parse(file string) (*Document, []error) {
return doc, []error{}
}

// ////////////////////////////////////////////////////////////////////////////////// //

// parseEntity method parse entity and return type, name and value of
// entity
func parseEntity(data string) (EntityType, string, string) {
Expand Down Expand Up @@ -483,7 +488,7 @@ func parseMethodComment(name string, data []string) *Method {
method.Desc = extractMethodDesc(data, index)
}

retValue := line[6:]
retValue := strutil.Substr(line, 6, 99999)

if negativeValRegexp.MatchString(retValue) {
continue
Expand All @@ -497,7 +502,7 @@ func parseMethodComment(name string, data []string) *Method {
method.Desc = extractMethodDesc(data, index)
}

echoValue := line[6:]
echoValue := strutil.Substr(line, 6, 99999)

if negativeValRegexp.MatchString(echoValue) {
continue
Expand Down
8 changes: 8 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ method11() {
method12() {
stub=1
}
# 1: ()
# Code:
# Echo:
# Example:
method13(){
stub=1
}
`

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
74 changes: 37 additions & 37 deletions shdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"strings"
"text/template"

"pkg.re/essentialkaos/ek.v8/arg"
"pkg.re/essentialkaos/ek.v8/env"
"pkg.re/essentialkaos/ek.v8/fmtc"
"pkg.re/essentialkaos/ek.v8/fmtutil"
"pkg.re/essentialkaos/ek.v8/fsutil"
"pkg.re/essentialkaos/ek.v8/path"
"pkg.re/essentialkaos/ek.v8/usage"
"pkg.re/essentialkaos/ek.v8/usage/update"
"pkg.re/essentialkaos/ek.v9/env"
"pkg.re/essentialkaos/ek.v9/fmtc"
"pkg.re/essentialkaos/ek.v9/fmtutil"
"pkg.re/essentialkaos/ek.v9/fsutil"
"pkg.re/essentialkaos/ek.v9/options"
"pkg.re/essentialkaos/ek.v9/path"
"pkg.re/essentialkaos/ek.v9/usage"
"pkg.re/essentialkaos/ek.v9/usage/update"

. "github.com/essentialkaos/shdoc/parser"
)
Expand All @@ -29,34 +29,34 @@ import (

const (
APP = "SHDoc"
VER = "0.4.0"
VER = "0.5.0"
DESC = "Tool for viewing and exporting docs for shell scripts"
)

const (
ARG_OUTPUT = "o:output"
ARG_TEMPLATE = "t:template"
ARG_NAME = "n:name"
ARG_NO_COLOR = "nc:no-color"
ARG_HELP = "h:help"
ARG_VER = "v:version"
OPT_OUTPUT = "o:output"
OPT_TEMPLATE = "t:template"
OPT_NAME = "n:name"
OPT_NO_COLOR = "nc:no-color"
OPT_HELP = "h:help"
OPT_VER = "v:version"
)

// ////////////////////////////////////////////////////////////////////////////////// //

var argMap = arg.Map{
ARG_OUTPUT: {},
ARG_TEMPLATE: {Value: "html"},
ARG_NAME: {},
ARG_NO_COLOR: {Type: arg.BOOL},
ARG_HELP: {Type: arg.BOOL, Alias: "u:usage"},
ARG_VER: {Type: arg.BOOL, Alias: "ver"},
var optMap = options.Map{
OPT_OUTPUT: {},
OPT_TEMPLATE: {Value: "html"},
OPT_NAME: {},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL, Alias: "u:usage"},
OPT_VER: {Type: options.BOOL, Alias: "ver"},
}

// ////////////////////////////////////////////////////////////////////////////////// //

func main() {
args, errs := arg.Parse(argMap)
args, errs := options.Parse(optMap)

if len(errs) != 0 {
fmtc.Println("Arguments parsing errors:")
Expand All @@ -68,16 +68,16 @@ func main() {
os.Exit(1)
}

if arg.GetB(ARG_NO_COLOR) {
if options.GetB(OPT_NO_COLOR) {
fmtc.DisableColors = true
}

if arg.GetB(ARG_VER) {
if options.GetB(OPT_VER) {
showAbout()
return
}

if arg.GetB(ARG_HELP) || len(args) == 0 {
if options.GetB(OPT_HELP) || len(args) == 0 {
showUsage()
return
}
Expand Down Expand Up @@ -125,11 +125,11 @@ func process(file string, pattern string) {
os.Exit(2)
}

if arg.GetS(ARG_NAME) != "" {
doc.Title = arg.GetS(ARG_NAME)
if options.GetS(OPT_NAME) != "" {
doc.Title = options.GetS(OPT_NAME)
}

if arg.GetS(ARG_OUTPUT) == "" {
if options.GetS(OPT_OUTPUT) == "" {
if pattern == "" {
simpleRender(doc)
} else {
Expand Down Expand Up @@ -233,14 +233,14 @@ func renderTemplate(doc *Document) {
projectDir := env.Get().GetS("GOPATH")
templateFile := path.Join(
projectDir, "src/github.com/essentialkaos/shdoc/templates",
arg.GetS(ARG_TEMPLATE)+".tpl",
options.GetS(OPT_TEMPLATE)+".tpl",
)

if !fsutil.CheckPerms("FRS", templateFile) {
printErrorAndExit("Can't read template %s - file does not exist or empty", templateFile)
}

outputFile := arg.GetS(ARG_OUTPUT)
outputFile := options.GetS(OPT_OUTPUT)

if fsutil.IsExist(outputFile) {
os.Remove(outputFile)
Expand Down Expand Up @@ -370,12 +370,12 @@ func printErrorAndExit(f string, a ...interface{}) {
func showUsage() {
info := usage.NewInfo("", "file")

info.AddOption(ARG_OUTPUT, "Path to output file", "file")
info.AddOption(ARG_TEMPLATE, "Name of template", "name")
info.AddOption(ARG_NAME, "Overwrite default name", "name")
info.AddOption(ARG_NO_COLOR, "Disable colors in output")
info.AddOption(ARG_HELP, "Show this help message")
info.AddOption(ARG_VER, "Show version")
info.AddOption(OPT_OUTPUT, "Path to output file", "file")
info.AddOption(OPT_TEMPLATE, "Name of template", "name")
info.AddOption(OPT_NAME, "Overwrite default name", "name")
info.AddOption(OPT_NO_COLOR, "Disable colors in output")
info.AddOption(OPT_HELP, "Show this help message")
info.AddOption(OPT_VER, "Show version")

info.AddExample(
"script.sh",
Expand Down

0 comments on commit 4be2160

Please sign in to comment.