Documentation
¶
Overview ¶
Package utilities provides helper functions for CLI input validation and error handling.
Index ¶
Constants ¶
const DefaultAssetsDirName = "images"
DefaultAssetsDirName is the assets directory used, relative to the posts directory, when no --assets-dir flag is given.
Variables ¶
This section is empty.
Functions ¶
func CliErrorHandler ¶
func CliErrorHandler(err error)
CliErrorHandler handles errors by printing them to stdout or stderr and exits if fatal.
func GetDirectoryFromInput ¶
GetDirectoryFromInput validates a path and returns it as an fs.FS.
func OpenAssetsDir ¶ added in v2.6.0
OpenAssetsDir opens the assets directory as an os.Root, so files served or copied from it cannot escape the directory via ".." or symbolic links.
When assetsDir is empty it defaults to <postsDir>/images. If the resolved directory does not exist, OpenAssetsDir returns a nil Root and nil error: asset support is silently off. Any other failure, such as the path not being a directory, is returned as an error.
The caller must Close a non-nil Root.
func RobotsOptions ¶
func RobotsOptions(c *cli.Command) ([]config.GeneratorOption, error)
RobotsOptions validates the sitemap and robots.txt flags and converts them into generator options. It is shared by the generate and serve subcommands, which expose the same flags.
It is called before any generation work so that contradictory flags fail fast:
- --robots-file together with --disable-robots is an error. One supplies a custom robots.txt and the other suppresses robots.txt entirely; honouring the disable would silently discard the user's file.
- --robots-file naming a missing or unreadable path is an error rather than a silent fallback to the default rules.
Types ¶
This section is empty.