cmd

package
v0.0.0-...-42c701e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const VERSION = "0.0.1"

Variables

View Source
var PreviewCmd = &cobra.Command{
	Use:   "preview",
	Short: "Preview HTML files in your default browser",
	Run: func(cmd *cobra.Command, args []string) {
		for _, doc := range cfg.Docs {
			files := Resolve(doc.Files)
			html := Compile(files, doc.Notice)

			tmpFile, _ := ioutil.TempFile(os.TempDir(), "sacred.*.html")
			tmpFile.Write(html)
			tmpFile.Close()

			openBrowser(fmt.Sprintf("file:///%s", tmpFile.Name()))
		}
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "sacred",
	Short: description,
	Long:  description,
}

RootCmd represents the base command when called without any subcommands

View Source
var UploadCmd = &cobra.Command{
	Use:   "upload",
	Short: "Uploads to Confluence API",
	Run: func(cmd *cobra.Command, args []string) {
		for _, doc := range cfg.Docs {
			files := Resolve(doc.Files)
			html := Compile(files, doc.Notice)

			if outputDir != "" {
				createHtmlFile(doc.Name, html)
			}

			client := confluence.NewClient(cfg.Auth.Domain, cfg.Auth.Token, nil)
			content, _, _ := client.ContentService.Get(doc.ContentId)

			body := confluence.ContentRequestPayload(content.Space.Key, content.Version.Number, doc.Name, string(html))
			client.ContentService.Update(doc.ContentId, body)
		}
	},
}

Functions

func Compile

func Compile(fileList []string, notice string) []byte

Compile files into markdown and combine

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func LoadConfig

func LoadConfig()

func MergeCredentials

func MergeCredentials(cfg *Configuration)

func Resolve

func Resolve(fileList []string) []string

Resolve interates through all files in all docs expanding globs and preserving uniqueness of the slice. This allows you to declare `DocConfiguration.Files` in the order you want and glob directories to fall back to alphabetical order.

Types

type AuthConfiguration

type AuthConfiguration struct {
	Token  string
	Domain string
}

type Configuration

type Configuration struct {
	Auth AuthConfiguration
	Docs []DocConfiguration
}

type DocConfiguration

type DocConfiguration struct {
	Name      string
	Notice    string
	Files     []string
	SpaceId   string
	ContentId string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL