Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.
Open
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
48 changes: 44 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,47 @@ package main

import (
"flag"
"github.com/go-ini/ini"
"log"

"github.com/philproctor/confluence-cli/client"
"github.com/philproctor/confluence-cli/command"
)

func parseIniConfig(iniFilePath string, config *client.ConfluenceConfig) error {
var cfg, err = ini.Load(iniFilePath)
if err != nil {
return err
}

config.Username = cfg.Section("").Key("username").String()
config.Password = cfg.Section("").Key("password").String()
config.URL = cfg.Section("").Key("url").String()

var debug, debugErr = cfg.Section("").Key("debug").Bool()
if debugErr != nil {
return err
}

config.Debug = debug
return nil
}

func main() {
var config = client.ConfluenceConfig{}
var options = command.OperationOptions{}
var config = client.ConfluenceConfig{}
var configFilePath string

var username string
var password string
var url string

flag.StringVar(&config.Username, "u", "", "Confluence username")
flag.StringVar(&config.Password, "p", "", "Confluence password")
flag.StringVar(&config.URL, "s", "", "The base URL of the Confluence page")
flag.StringVar(&username, "u", "", "Confluence username")
flag.StringVar(&password, "p", "", "Confluence password")
flag.StringVar(&url, "s", "", "The base URL of the Confluence page")
flag.StringVar(&configFilePath, "config", "", "Path to the configuration " +
"file that contains authentication credentials. Command-line parameters: " +
"`-u`, `-p` and `-s` will override settings found inside the config file.")
flag.StringVar(&options.Title, "t", "", "Title to use for a new page")
flag.StringVar(&options.SpaceKey, "k", "", "Space key to use")
flag.StringVar(&options.Filepath, "f", "", "Path to the file to upload as the page contents")
Expand All @@ -26,5 +55,16 @@ func main() {
flag.BoolVar(&options.CleanAdoc, "clean-adoc", false, "If the attached HTML was generated by AsciiDoc, attempt to normalize for Confluence")
flag.Parse()

if configFilePath != "" {
var err = parseIniConfig(configFilePath, &config)
if err != nil {
log.Fatal(err)
}
}

if username != "" { config.Username = username }
if password != "" { config.Password = password }
if url != "" { config.URL = url }

command.Run(flag.Arg(0), &config, &options)
}