diff --git a/cmd/libasciidoc/root_cmd.go b/cmd/libasciidoc/root_cmd.go index c75f85aa..c4d5fc20 100644 --- a/cmd/libasciidoc/root_cmd.go +++ b/cmd/libasciidoc/root_cmd.go @@ -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", @@ -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 @@ -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 } diff --git a/cmd/libasciidoc/root_cmd_test.go b/cmd/libasciidoc/root_cmd_test.go index f9b7b493..d8e320d0 100644 --- a/cmd/libasciidoc/root_cmd_test.go +++ b/cmd/libasciidoc/root_cmd_test.go @@ -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(`