Skip to content

Commit

Permalink
Refactor (#72)
Browse files Browse the repository at this point in the history
* Minor updates, cleaning up dev branch

* Updated embedded dojoConfig.yml to latest version

* More clean-up for 2.0.x and start of work on supporting Debian install targets

* Update for new embedded version

* Workaround Python 3.8 bug that kinda broke 1.15.1 (and maybe other releases)

* Bump version for 2 bugfixes

* Bug fixes for 2 bugs impacting 1.15.x installs on 'iron' (#23) (#24)

* Fix bug in installing PostgreSQL DB install process
Remove use of legacy resolver for pip installs
Ensure there's an admin email address provided, use default of not
Ensure special characters in passwords are handled correctly when setting the intiial web admin password

* Update version number to 1.1.7

* Merge master back into dev (#34)

* Fix a couple of bugs (#32)

* Fix bug in installing PostgreSQL DB install process

* Remove use of legacy resolver for pip installs

* Ensure there's an admin email address provided, use default if not

* Ensure special characters in passwords are handled correctly when setting the initial web admin password

* Bump version number to 1.1.7 (#33)

* Update version number to 1.1.7

* Removed debugging messages

* Fix typo in link to upgrade instructions

* Added link to post-install and upgrade documentation

* Update embedded files

* Updated go modules (depenencies), removed go-bindata to use go:embed, added libcurl4-openssl-dev needed by pycurl

* Remove bindata.go - no longer necessary

* Fix multiple issues - download timeout, newer Ubuntu distros, etc

* Initial commit of refactor

* Part 1 of major refactor

* Uncommented a line that shouldn't have been

* Part 2 of major refactor - cleanup redundanct code

* Completed majority of the refactor, added beta RHEL support

* Refactor complete
  • Loading branch information
mtesauro authored Apr 2, 2023
1 parent b2c2325 commit 05eb6bc
Show file tree
Hide file tree
Showing 78 changed files with 25,733 additions and 3,475 deletions.
85 changes: 17 additions & 68 deletions args.go → cmd/args.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package main
package cmd

import (
"flag"
"fmt"
"io/ioutil"
"os"
)

type launchArgs struct {
Dev bool
Default bool
Componse bool // TODO: Implement this
K8s bool // TODO: Implement this
}

func readArgs() launchArgs {
//TODO TUrn me to a log writer fmt.Println("Called readArgs")
// readArgs() takes no arguements and returns filled launchArgs struct unless
// there are errors in the arguments or the argument provided calls for an
// early exist such as --version or --help
func readArgs(d *DDConfig) {
d.traceMsg("Called readArgs")
// Read in the supported command-line options
var version, help, v, h bool
opts := launchArgs{}
flag.BoolVar(&opts.Default, "default", false, "Do an install based on default config values")
flag.BoolVar(&opts.Dev, "dev", false, "Do a development install with known config values")
flag.BoolVar(&d.defInstall, "default", false, "Do an install based on default config values")
flag.BoolVar(&version, "version", false, "Print the version and exit")
flag.BoolVar(&v, "v", false, "Print the version and exit")
flag.BoolVar(&help, "help", false, "Print the help message and exit")
Expand All @@ -34,21 +27,13 @@ func readArgs() launchArgs {
}
// Print version
if version || v {
fmt.Printf("godojo version %s\n", ver)
fmt.Printf("godojo version %s\n", d.ver)
os.Exit(0)
}

// Handle double options (dev and default currently)
if opts.Dev && opts.Default {
// Only 1 option should be provided, not both
fmt.Println("Error: godojo only supports a single install option")
fmt.Println("Both -dev and --default have been provided so exiting.")
os.Exit(1)
}

// Handle special install cases of default and dev
if opts.Default || opts.Dev {
return opts
// Handle special install case of default installs
if d.defInstall {
return
}

// See if the dojoConfig.yml is in the local directory
Expand All @@ -58,15 +43,16 @@ func readArgs() launchArgs {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
_, err = os.Stat(path + "/" + cf)
_, err = os.Stat(path + "/" + d.cf)
if err != nil {
// No config file found, so create one and exit
createDefaultConfig(cf, true)
writeDefaultConfig(d.cf, true)
}
traceMsg("Reached the end of readArgs")
return opts

d.traceMsg("Reached the end of readArgs")
}

// printHelp takes no arguements and prints godojo's help content to stdout
func printHelp() {
// Output the help info
fmt.Println("")
Expand All @@ -81,9 +67,6 @@ func printHelp() {
fmt.Println(" -default")
fmt.Println(" OPTIONAL - Do an install based on the default dojoConfig.yml values")
fmt.Println(" Must be used alone and without other arguments")
fmt.Println(" -dev")
fmt.Println(" OPTIONAL - Do an dev install with fixed values especially for testing")
fmt.Println(" Must be used alone and without other arguments")
fmt.Println(" -help, -h")
fmt.Println(" Print this help message and exit, ignoring all other arguments")
fmt.Println(" -version, -v")
Expand All @@ -98,40 +81,6 @@ func printHelp() {
fmt.Println(" (Either creates a default config file or installs based on the config file in the same directory)")
fmt.Println("$ ./godojo -dev")
fmt.Println(" (Does a dev aka development/test install using known and fixed values for the installation")
// TODO Consider an example of overriding with an env variable
fmt.Println("")
}

func createDefaultConfig(c string, ex bool) {
// Get the current working directory for future operations
path, err := os.Getwd()
if err != nil {
fmt.Println("Unable to determine current working directory, exiting...")
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}

// Extract the embedded config file
f, err := embd.ReadFile(embdConfig)
if err != nil {
// file was not found.
fmt.Println("Unable to extract embedded config file")
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}

// Write out the embedded default dojoConfig.yml
err = ioutil.WriteFile(path+"/"+c, f, 0644)
if err != nil {
// Cannot write config file
fmt.Printf("Unable to write configuration file in %s, exiting...\n", path)
fmt.Printf("Error: %v\n", err)
}

if ex {
fmt.Println("\nNOTE: A dojoConfig.yml file was not found in the current directory:")
fmt.Printf("\t%s\nA default configuration file was written there.\n\n", path)
fmt.Println("Please review the configuration settings, adjusting as needed and")
fmt.Println("re-run the godojo installer to begin the install you configured.")
os.Exit(0)
}
}
Loading

0 comments on commit 05eb6bc

Please sign in to comment.