Skip to content

Commit

Permalink
add support for short man command
Browse files Browse the repository at this point in the history
1. Allows doc writing in markdown
2. Automatically generate txt docs and builds it into binary
3. paging support for viewing docs using short man command
4. Update .gitignore ot ignore generated files
  • Loading branch information
wlan0 committed Nov 15, 2017
1 parent a497b4e commit a9610b0
Show file tree
Hide file tree
Showing 15 changed files with 778 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/bin

generated/*.txt
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.8

RUN cat /etc/os-release

RUN apt-get update

RUN wget http://http.us.debian.org/debian/pool/non-free/x/xml2rfc/xml2rfc_2.4.8-1_all.deb

#Install binaries from debian needed for golang, python, xml2rfc, and mmark
RUN apt-get -y install python python-lxml

RUN dpkg -i xml2rfc_2.4.8-1_all.deb
RUN apt-get install -f

RUN go get github.com/BurntSushi/toml
RUN go get github.com/miekg/mmark/...
RUN go get -u github.com/jteeuwen/go-bindata/...

RUN mkdir -p /go/src/github.com/koki/short
WORKDIR /go/src/github.com/koki/short
COPY .* /go/src/github.com/koki/short/

ENTRYPOINT ["scripts/ci.sh"]
38 changes: 38 additions & 0 deletions cmd/man.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"bytes"
"index/suffixarray"

"github.com/spf13/cobra"

"github.com/koki/short/generated"
"github.com/koki/short/pager"
"github.com/koki/short/util"
)

var (
manCommand = &cobra.Command{
Use: "man",
Short: "Reference and Examples for resources and conversions",
Long: "Reference and Examples for koki <-> kubernetes conversions",
RunE: man,
Args: cobra.ExactArgs(1),
SilenceUsage: true,
}
)

func man(c *cobra.Command, args []string) error {
resourceName := args[0]
resourcePath := "../generated/" + resourceName + ".txt"
data, err := generated.Asset(resourcePath)
if err != nil {
return util.UsageErrorf(c.CommandPath, "Unsupported resource name %s", resourceName)
}

index := suffixarray.New(data)

buf := bytes.NewBuffer(data)
p := pager.NewPager(buf, index)
return p.Render()
}
9 changes: 6 additions & 3 deletions cmd/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Full documentation available at https://docs.koki.io/short
`,
RunE: short,
SilenceUsage: true,
Args: cobra.ExactArgs(1),
Example: `
# Find the shorthand representation of kubernetes objects
short man pod
short man deployment
# Convert existing kubernetes manifestes to shorthand format
short -f pod.yaml
Expand All @@ -44,7 +44,10 @@ Full documentation available at https://docs.koki.io/short
short -k -f pod_short.yaml
# Output to file
short -f pod.yaml -o pod_short.yaml
short -f pod.yaml > pod_short.yaml
# Output as yaml* or json
short -f pod.yaml -o json
`,
}

Expand Down Expand Up @@ -75,7 +78,7 @@ func init() {
flag.CommandLine.Parse([]string{})

RootCmd.AddCommand(versionCmd)
//RootCmd.AddCommand(manCommand)
RootCmd.AddCommand(manCommand)
}

func short(c *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (

versionCmd = &cobra.Command{
Use: "version",
Short: "prints the version of short",
Short: "Prints the version of short",
Run: func(*cobra.Command, []string) {
fmt.Printf("koki/shorthand: %s\n", GITCOMMIT)
},
Expand Down
54 changes: 54 additions & 0 deletions docs/pod.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
%%%
title = "Pod Conversion Conventions"
abbrev = "Pod"
category = "info"
area = "Koki Short"
keyword = ["Pod"]

[[author]]
fullname = "Caascade Labs, Inc."
%%%

.# Abstract

This document provides the details of the conversion mechanisms between Kubernetes Pod syntax and Koki Short syntax

{mainmatter}

# Introduction {#introduction}

A Pod is the unit of execution when using the Kubernetes orchestrator. It is defined in the api group core/v1. This version of Koki Short supports all valid Pod definitions of Kubernetes Versions \[v1.0 - v1.8]

A> No data is lost when converting between koki and kubernetes types

# Conversion from Kubernetes to Koki

The Kubernetes API Object for Pod has a kind Key that always refers to value "Pod". This information is redundant, since Kubernetes parsers identify the type, and provide us with the Pod object, therefore this Kind field is removed in Koki and instead a new top level key called pod is used to denote a pod.

A kubernetes pod definitions looks like

~~~
apiVersion: v1
kind: pod
metadata:
name: pod_name
...
~~~

A koki pod definition written using Short syntax would look like

~~~
pod:
name: pod_name
...
~~~

As you can see, without getting into the most reductive parts, pod definitions in koki short syntax already look cleaner.

# Conversion from Koki to Kubernetes



# Examples

{backmatter}
Loading

0 comments on commit a9610b0

Please sign in to comment.