2025-03-11 11:31:16 -06:00
package util
import (
2025-04-15 21:30:59 +02:00
altsrc "github.com/urfave/cli-altsrc/v3"
altsrctoml "github.com/urfave/cli-altsrc/v3/toml"
"github.com/urfave/cli/v3"
2025-03-11 11:31:16 -06:00
)
2025-04-15 21:30:59 +02:00
var filename = ConfigFilePath ( )
var configFile = altsrc . NewStringPtrSourcer ( & filename )
2025-03-11 11:31:16 -06:00
var Flags = [ ] cli . Flag {
2025-04-15 21:30:59 +02:00
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "files" ,
Aliases : [ ] string { "f" } ,
Value : "" ,
Usage : "use specified markdown file(s) for converting to html. Supports file globbing patterns (needs to be quoted)." ,
TakesFile : true ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_FILES" ) , altsrctoml . TOML ( "files" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "continue-on-error" ,
Value : false ,
Usage : "don't exit if an error occurs while processing a file, continue processing remaining files." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_CONTINUE_ON_ERROR" ) , altsrctoml . TOML ( "continue_on_error" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "compile-only" ,
Value : false ,
Usage : "show resulting HTML and don't update Confluence page content." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_COMPILE_ONLY" ) , altsrctoml . TOML ( "compile_only" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "dry-run" ,
Value : false ,
Usage : "resolve page and ancestry, show resulting HTML and exit." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_DRY_RUN" ) , altsrctoml . TOML ( "dry_run" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "edit-lock" ,
Value : false ,
Aliases : [ ] string { "k" } ,
Usage : "lock page editing to current user only to prevent accidental manual edits over Confluence Web UI." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_EDIT_LOCK" ) , altsrctoml . TOML ( "edit_lock" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "drop-h1" ,
Value : false ,
Aliases : [ ] string { "h1_drop" } ,
Usage : "don't include the first H1 heading in Confluence output." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_H1_DROP" ) , altsrctoml . TOML ( "drop_h1" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "strip-linebreaks" ,
Value : false ,
Aliases : [ ] string { "L" } ,
2025-05-29 01:21:02 +02:00
Usage : "remove linebreaks inside of tags, to accommodate non-standard Confluence behavior" ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_STRIP_LINEBREAKS" ) , altsrctoml . TOML ( "strip_linebreaks" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "title-from-h1" ,
Value : false ,
Aliases : [ ] string { "h1_title" } ,
Usage : "extract page title from a leading H1 heading. If no H1 heading on a page exists, then title must be set in the page metadata." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_H1_TITLE" ) , altsrctoml . TOML ( "title_from_h1" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "title-append-generated-hash" ,
Value : false ,
Usage : "appends a short hash generated from the path of the page (space, parents, and title) to the title" ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_TITLE_APPEND_GENERATED_HASH" ) , altsrctoml . TOML ( "title_append_generated_hash" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "minor-edit" ,
Value : false ,
Usage : "don't send notifications while updating Confluence page." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_MINOR_EDIT" ) , altsrctoml . TOML ( "minor_edit" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "version-message" ,
Value : "" ,
Usage : "add a message to the page version, to explain the edit (default: \"\")" ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_VERSION_MESSAGE" ) , altsrctoml . TOML ( "version_message" , configFile ) ) ,
} ,
& cli . StringFlag {
Name : "color" ,
Value : "auto" ,
Usage : "display logs in color. Possible values: auto, never." ,
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_COLOR" ) ,
altsrctoml . TOML ( "color" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "log-level" ,
Value : "info" ,
Usage : "set the log level. Possible values: TRACE, DEBUG, INFO, WARNING, ERROR, FATAL." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_LOG_LEVEL" ) , altsrctoml . TOML ( "log_level" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "username" ,
Aliases : [ ] string { "u" } ,
Value : "" ,
Usage : "use specified username for updating Confluence page." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_USERNAME" ) ,
altsrctoml . TOML ( "username" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "password" ,
Aliases : [ ] string { "p" } ,
Value : "" ,
Usage : "use specified token for updating Confluence page. Specify - as password to read password from stdin, or your Personal access token. Username is not mandatory if personal access token is provided. For more info please see: https://developer.atlassian.com/server/confluence/confluence-server-rest-api/#authentication." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_PASSWORD" ) , altsrctoml . TOML ( "password" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "target-url" ,
Aliases : [ ] string { "l" } ,
Value : "" ,
Usage : "edit specified Confluence page. If -l is not specified, file should contain metadata (see above)." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_TARGET_URL" ) , altsrctoml . TOML ( "target_url" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "base-url" ,
Aliases : [ ] string { "b" , "base_url" } ,
Value : "" ,
Usage : "base URL for Confluence. Alternative option for base_url config field." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_BASE_URL" ) ,
altsrctoml . TOML ( "base_url" , configFile ) ) ,
} ,
2025-03-11 11:31:16 -06:00
& cli . StringFlag {
2025-05-29 01:21:02 +02:00
Name : "config" ,
Aliases : [ ] string { "c" } ,
Value : ConfigFilePath ( ) ,
Usage : "use the specified configuration file." ,
TakesFile : true ,
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_CONFIG" ) ) ,
2025-04-15 21:30:59 +02:00
Destination : & filename ,
2025-03-11 11:31:16 -06:00
} ,
2025-04-15 21:30:59 +02:00
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "ci" ,
Value : false ,
Usage : "run on CI mode. It won't fail if files are not found." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_CI" ) , altsrctoml . TOML ( "ci" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "space" ,
Value : "" ,
Usage : "use specified space key. If the space key is not specified, it must be set in the page metadata." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_SPACE" ) , altsrctoml . TOML ( "space" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "parents" ,
Value : "" ,
Usage : "A list containing the parents of the document separated by parents-delimiter (default: '/'). These will be prepended to the ones defined in the document itself." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_PARENTS" ) , altsrctoml . TOML ( "parents" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "parents-delimiter" ,
Value : "/" ,
Usage : "The delimiter used for the parents list" ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_PARENTS_DELIMITER" ) , altsrctoml . TOML ( "parents_delimiter" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "mermaid-provider" ,
Value : "cloudscript" ,
Usage : "defines the mermaid provider to use. Supported options are: cloudscript, mermaid-go." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_MERMAID_PROVIDER" ) , altsrctoml . TOML ( "mermaid_provider" , configFile ) ) ,
} ,
& cli . FloatFlag {
2025-03-11 11:31:16 -06:00
Name : "mermaid-scale" ,
Value : 1.0 ,
Usage : "defines the scaling factor for mermaid renderings." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_MERMAID_SCALE" ) , altsrctoml . TOML ( "mermaid_scale" , configFile ) ) ,
} ,
& cli . StringFlag {
2025-03-11 11:31:16 -06:00
Name : "include-path" ,
Value : "" ,
Usage : "Path for shared includes, used as a fallback if the include doesn't exist in the current directory." ,
TakesFile : true ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_INCLUDE_PATH" ) , altsrctoml . TOML ( "include_path" , configFile ) ) ,
} ,
& cli . BoolFlag {
2025-03-11 11:31:16 -06:00
Name : "changes-only" ,
Value : false ,
Usage : "Avoids re-uploading pages that haven't changed since the last run." ,
2025-04-15 21:30:59 +02:00
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_CHANGES_ONLY" ) , altsrctoml . TOML ( "changes_only" , configFile ) ) ,
} ,
2025-05-29 01:21:02 +02:00
& cli . FloatFlag {
Name : "d2-scale" ,
Value : 1.0 ,
Usage : "defines the scaling factor for d2 renderings." ,
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_D2_SCALE" ) , altsrctoml . TOML ( "d2_scale" , configFile ) ) ,
} ,
& cli . StringSliceFlag {
Name : "features" ,
Value : [ ] string { "mermaid" } ,
Usage : "Enables optional features. Current features: d2, mermaid" ,
Sources : cli . NewValueSourceChain ( cli . EnvVar ( "MARK_FEATURES" ) , altsrctoml . TOML ( "features" , configFile ) ) ,
} ,
2025-03-11 11:31:16 -06:00
}