diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aacee6..266fdd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.2.0] - 2023-03-12 + +### Added + + - Enable stopping server using cli flag + ## [0.1.1] - 2023-02-27 ### Fixed @@ -15,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Initial version, providing a working proof-of-concept. -[0.1.1]: https://github.com/cluttrdev/showdown/compare/v0.1.1...v0.1.0 +[0.2.0]: https://github.com/cluttrdev/showdown/compare/v0.1.1...v0.2.0 +[0.1.1]: https://github.com/cluttrdev/showdown/compare/v0.1.0...v0.1.1 [0.1.0]: https://github.com/cluttrdev/showdown/releases/tag/v0.1.0 - diff --git a/README.md b/README.md index 3219d86..647fa4a 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,6 @@ tar -zxf showdown_${RELEASE_TAG}_linux_x86_64.tar.gz showdown install ./showdown /usr/local/bin/showdown ``` -Alternatively, you can install it using the standard Go tools. - -```shell -go install github.com/cluttrdev/showdown@latest -``` - ## Usage To preview a Markdown formatted file `example.md` simply run diff --git a/cmd/showdown/app.go b/cmd/showdown/app.go index 635ff26..11e04af 100644 --- a/cmd/showdown/app.go +++ b/cmd/showdown/app.go @@ -89,3 +89,9 @@ func (app *Application) render() ([]byte, error) { return out, nil } + +func StopServer(port uint16) error { + url := fmt.Sprintf("http://127.0.0.1:%d/shutdown", port) + _, err := http.Get(url) + return err +} diff --git a/cmd/showdown/main.go b/cmd/showdown/main.go index 01cc7df..2a18f55 100644 --- a/cmd/showdown/main.go +++ b/cmd/showdown/main.go @@ -10,15 +10,27 @@ import ( var cmd = &cobra.Command{ Use: "showdown [file]", Short: "Live markdown previewer", - Args: cobra.ExactArgs(1), + Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - file := args[0] - port, err := cmd.Flags().GetUint16("port") if err != nil { return err } + stop, err := cmd.Flags().GetBool("stop") + if err != nil { + return err + } + + if stop { + return StopServer(port) + } + + if len(args) == 0 { + return fmt.Errorf("Missing file argument") + } + file := args[0] + app := NewApplication(file) return app.run(port) }, @@ -32,5 +44,6 @@ func main() { } func init() { - cmd.Flags().Uint16P("port", "p", 1337, "the port on which the server will listen") + cmd.Flags().Uint16P("port", "p", 1337, "the port the server listens on") + cmd.Flags().Bool("stop", false, "stop a running server") }