Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd): add flag to suppress header/footer #95

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/libasciidoc/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var logLevel string
// NewRootCmd returns the root command
func NewRootCmd() *cobra.Command {
var source string
var noHeaderFooter bool
rootCmd := &cobra.Command{
Use: "libasciidoc",
Short: "libasciidoc is a tool to generate an html output from an asciidoc file",
Expand All @@ -25,10 +26,10 @@ func NewRootCmd() *cobra.Command {
return fmt.Errorf("flag 'source' is required")
}
if cmd.Flag("source").Value.String() == "-" {
_, err = libasciidoc.ConvertToHTML(context.Background(), os.Stdin, cmd.OutOrStdout(), renderer.IncludeHeaderFooter(true))
_, err = libasciidoc.ConvertToHTML(context.Background(), os.Stdin, cmd.OutOrStdout(), renderer.IncludeHeaderFooter(!noHeaderFooter))
} else {
source := cmd.Flag("source").Value.String()
_, err = libasciidoc.ConvertFileToHTML(context.Background(), source, cmd.OutOrStdout(), renderer.IncludeHeaderFooter(true)) //renderer.IncludeHeaderFooter(true)
_, err = libasciidoc.ConvertFileToHTML(context.Background(), source, cmd.OutOrStdout(), renderer.IncludeHeaderFooter(!noHeaderFooter)) //renderer.IncludeHeaderFooter(true)
}
if err != nil {
return err
Expand All @@ -48,6 +49,7 @@ func NewRootCmd() *cobra.Command {
}
flags := rootCmd.Flags()
flags.StringVarP(&source, "source", "s", "", "the path to the asciidoc source to process. Use '-' for reading from stdin")
flags.BoolVarP(&noHeaderFooter, "no-header-footer", "n", false, "Do not render header/footer (Default: false)")
rootCmd.PersistentFlags().StringVar(&logLevel, "log", "warning", "log level to set {debug, info, warning, error, fatal, panic}")
return rootCmd
}
14 changes: 14 additions & 0 deletions cmd/libasciidoc/root_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ var _ = Describe("root cmd", func() {
require.Error(GinkgoT(), err)
})

It("should render without header/footer", func() {
// given
root := main.NewRootCmd()
buf := new(bytes.Buffer)
root.SetOutput(buf)
root.SetArgs([]string{"-n", "-s", "test/test.adoc"})
// when
err := root.Execute()
// then
require.NoError(GinkgoT(), err)
require.NotEmpty(GinkgoT(), buf)
Expect(buf.String()).ToNot(ContainSubstring(`<div id="footer">`))
})

It("should process stdin", func() {
// given
root := main.NewRootCmd()
Expand Down