Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Simpler user responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
MickMake committed Jun 29, 2020
1 parent 27d4bf5 commit 05b3b92
Show file tree
Hide file tree
Showing 24 changed files with 1,264 additions and 787 deletions.
152 changes: 69 additions & 83 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func init() {
}
}

//rootCmd.Flags().BoolVarP(&CmdScribe.Debug, loadTools.FlagDebug ,"d", false, ux.SprintfBlue("DEBUG mode."))

CmdScribe.SetHelp(rootCmd)
}
}
Expand Down Expand Up @@ -125,6 +127,7 @@ func gbRootFunc(cmd *cobra.Command, args []string) {

func Execute() *ux.State {
for range onlyOnce {
//foo := CmdScribe.GetCmd()
err := rootCmd.Execute()
if err != nil {
CmdScribe.State.SetError(err)
Expand Down
36 changes: 18 additions & 18 deletions deploywp/deploywp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,55 +67,55 @@ func (dwp *TypeDeployWp) GetSourceBuild() bool {


// ////////////////////////////////////////////////////////////////////////////////
// Target
func (dwp *TypeDeployWp) GetTarget() *Target {
return &dwp.Target
// Destination
func (dwp *TypeDeployWp) GetDestination() *Destination {
return &dwp.Destination
}


// ////////////////////////////////////////////////////////////////////////////////
// Target.Files
func (dwp *TypeDeployWp) GetTargetFiles(ftype string) *FilesArray {
// Destination.Files
func (dwp *TypeDeployWp) GetDestinationFiles(ftype string) *FilesArray {
if state := dwp.IsNil(); state.IsError() {
return &FilesArray{}
}
return dwp.Target.GetFiles(ftype)
return dwp.Destination.GetFiles(ftype)
}


// ////////////////////////////////////////////////////////////////////////////////
// Target.Paths
func (dwp *TypeDeployWp) GetTargetPaths() *Paths {
// Destination.Paths
func (dwp *TypeDeployWp) GetDestinationPaths() *Paths {
if state := dwp.IsNil(); state.IsError() {
return &Paths{}
}
return &dwp.Target.Paths
return &dwp.Destination.Paths
}
func (dwp *TypeDeployWp) GetTargetAbsPaths() *Paths {
func (dwp *TypeDeployWp) GetDestinationAbsPaths() *Paths {
if state := dwp.IsNil(); state.IsError() {
return &Paths{}
}
return &dwp.Target.AbsPaths
return &dwp.Destination.AbsPaths
}


// ////////////////////////////////////////////////////////////////////////////////
// Target.Revisions
func (dwp *TypeDeployWp) GetTargetRevision(host string) *TargetRevision {
// Destination.Revisions
func (dwp *TypeDeployWp) GetDestinationRevision(host string) *Target {
if state := dwp.IsNil(); state.IsError() {
return &TargetRevision{}
return &Target{}
}
return dwp.Target.GetRevisionByHost(host)
return dwp.Destination.GetTargetByHost(host)
}


// ////////////////////////////////////////////////////////////////////////////////
// Target.Providers
func (dwp *TypeDeployWp) GetTargetProvider(provider string) *Provider {
// Destination.Providers
func (dwp *TypeDeployWp) GetDestinationProvider(provider string) *Provider {
if state := dwp.IsNil(); state.IsError() {
return &Provider{}
}
return dwp.Target.GetProviderByName(provider)
return dwp.Destination.GetProviderByName(provider)
}


Expand Down
284 changes: 284 additions & 0 deletions deploywp/destination.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
package deploywp

import (
"github.com/jinzhu/copier"
"github.com/newclarity/scribeHelpers/toolRuntime"
"github.com/newclarity/scribeHelpers/toolTypes"
"github.com/newclarity/scribeHelpers/ux"
)


const DefaultDestinationBasePath = "/tmp/deploywp"

type Destination struct {
Files Files `json:"files"`
Paths Paths `json:"paths"`
Providers Providers `json:"providers"` // mapstructure:",squash"`
Targets Targets `json:"targets"` // mapstructure:",squash"`

AbsPaths Paths
AbsFiles Files

selectedHost *Host // Should be set to the selected host_name from arg[0]
selectedHostName string // Should be set to the selected host_name from arg[0]

Valid bool
runtime *toolRuntime.TypeRuntime
state *ux.State
}

func (d *Destination) New(runtime *toolRuntime.TypeRuntime) *Destination {
runtime = runtime.EnsureNotNil()
return &Destination{
Files: *((*Files).New(&Files{}, runtime)),
Paths: *((*Paths).New(&Paths{}, runtime)),
Providers: *((*Providers).New(&Providers{}, runtime)),
Targets: *((*Targets).New(&Targets{}, runtime)),
AbsPaths: *((*Paths).New(&Paths{}, runtime)),
AbsFiles: *((*Files).New(&Files{}, runtime)),

Valid: true,
runtime: runtime,
state: ux.NewState(runtime.CmdName, runtime.Debug),
}
}

func (d *Destination) IsNil() *ux.State {
if state := ux.IfNilReturnError(d); state.IsError() {
return state
}
d.state = d.state.EnsureNotNil()
return d.state
}

func (d *Destination) IsValid() bool {
if state := ux.IfNilReturnError(d); state.IsError() {
return false
}
for range onlyOnce {
if d.Files.IsNotValid() {
d.state = d.Files.state
d.Valid = false
break
}
if d.Paths.IsNotValid() {
d.state = d.Paths.state
d.Valid = false
break
}
if d.Providers.IsNotValid() {
//d.state = d.Providers.state
d.Valid = false
break
}
if d.Targets.IsNotValid() {
//d.state = d.Revisions.state
d.Valid = false
break
}

if d.AbsPaths.IsNotValid() {
d.state = d.AbsPaths.state
d.Valid = false
break
}
if d.AbsFiles.IsNotValid() {
d.state = d.AbsFiles.state
d.Valid = false
break
}

d.Valid = true
}
return d.Valid
}
func (d *Destination) IsNotValid() bool {
return !d.IsValid()
}

func (d *Destination) Process() *ux.State {
if state := d.IsNil(); state.IsError() {
return state
}

for range onlyOnce {
err := copier.Copy(&d.AbsPaths, &d.Paths)
d.state.SetError(err)
if d.state.IsError() {
break
}

d.state = d.Providers.Process(d.runtime)
if d.state.IsError() {
break
}

d.state = d.Targets.Process(d.runtime)
if d.state.IsError() {
break
}

if d.Paths.BasePath == "" {
d.Paths.BasePath = DefaultDestinationBasePath
}
//d.state = d.Paths.GetBasePath(d.Repository.GetUrlAsDir())
selectedProvider := d.Providers.GetByName(d.selectedHost.Provider)
d.state = d.Paths.AppendBasePath(d.selectedHost.HostName, selectedProvider.Meta.SiteName)
if d.state.IsError() {
break
}

d.AbsPaths.BasePath = d.Paths.BasePath
d.state = d.AbsPaths.ExpandPaths()
d.state.SetError(err)
if d.state.IsError() {
break
}

d.AbsFiles.Copy.Append(&d.Files.Copy)
d.AbsFiles.Delete.Append(&d.Files.Delete)
d.AbsFiles.Exclude.Append(&d.Files.Exclude)
d.AbsFiles.Keep.Append(&d.Files.Keep)

d.state = d.AbsFiles.Process(d.AbsPaths)
if d.state.IsError() {
break
}

d.state = d.Files.Process(d.Paths)
if d.state.IsError() {
break
}

d.Valid = true
}

return d.state
}


// ////////////////////////////////////////////////////////////////////////////////
// Files
func (d *Destination) GetFiles(ftype string) *FilesArray {
var ret *FilesArray
if state := d.IsNil(); state.IsError() {
return &FilesArray{}
}

for range onlyOnce {
ret = d.Files.GetFiles(ftype)
}

return ret
}


// ////////////////////////////////////////////////////////////////////////////////
// Paths
func (d *Destination) GetPaths(abs ...interface{}) *Paths {
var ret *Paths
if state := d.IsNil(); state.IsError() {
return &Paths{}
}

for range onlyOnce {
if toolTypes.ReflectBoolArg(abs) {
ret = &d.AbsPaths
break
}

ret = &d.Paths
}

return ret
}


func (d *Destination) GetBasePath() string {
if state := d.IsNil(); state.IsError() {
return ""
}
return d.Paths.BasePath
}


// ////////////////////////////////////////////////////////////////////////////////
// Providers
func (d *Destination) GetProviderByName(provider string) *Provider {
var ret *Provider
if state := d.IsNil(); state.IsError() {
return ret
}
return d.Providers.GetByName(provider)
}
func (d *Destination) GetProviderBySiteId(siteId string) *Provider {
var ret *Provider
if state := d.IsNil(); state.IsError() {
return ret
}
ret = d.Providers.GetBySiteId(siteId)
return ret
}


// ////////////////////////////////////////////////////////////////////////////////
// Revisions
func (d *Destination) GetTargetByHost(host string) *Target {
var ret *Target
if state := d.IsNil(); state.IsError() {
return &Target{state: state}
}
ret = d.Targets.GetByHost(host)
return ret
}

func (d *Destination) GetTargetByName(ref string) *Target {
var ret *Target
if state := d.IsNil(); state.IsError() {
return &Target{state: state}
}
ret = d.Targets.GetByRefName(ref)
return ret
}

//func (d *Destination) SelectHost(host string) *ux.State {
// if state := d.IsNil(); state.IsError() {
// return state
// }
//
// for range onlyOnce {
// d.selectedHost = d.GetTargetByHost(host)
// d.selectedHostName = host
// }
//
// return d.state
//}


func (d *Destination) GetSelectedHost() *Host {
if state := d.IsNil(); state.IsError() {
return &Host{state: state}
}
return d.selectedHost
}


func (d *Destination) SetDestinationHost(host *Host) *ux.State {
if state := d.IsNil(); state.IsError() {
return state
}

for range onlyOnce {
if host == nil {
d.state.SetError("Selected host is nil.")
break
}

d.selectedHost = host
d.selectedHostName = host.HostName

d.state.SetOk()
}

return d.state
}
Loading

0 comments on commit 05b3b92

Please sign in to comment.