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

Commit 05b3b92

Browse files
committed
Simpler user responses.
1 parent 27d4bf5 commit 05b3b92

24 files changed

+1264
-787
lines changed

.idea/workspace.xml

Lines changed: 69 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ func init() {
8585
}
8686
}
8787

88+
//rootCmd.Flags().BoolVarP(&CmdScribe.Debug, loadTools.FlagDebug ,"d", false, ux.SprintfBlue("DEBUG mode."))
89+
8890
CmdScribe.SetHelp(rootCmd)
8991
}
9092
}
@@ -125,6 +127,7 @@ func gbRootFunc(cmd *cobra.Command, args []string) {
125127

126128
func Execute() *ux.State {
127129
for range onlyOnce {
130+
//foo := CmdScribe.GetCmd()
128131
err := rootCmd.Execute()
129132
if err != nil {
130133
CmdScribe.State.SetError(err)

deploywp/deploywp.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,55 +67,55 @@ func (dwp *TypeDeployWp) GetSourceBuild() bool {
6767

6868

6969
// ////////////////////////////////////////////////////////////////////////////////
70-
// Target
71-
func (dwp *TypeDeployWp) GetTarget() *Target {
72-
return &dwp.Target
70+
// Destination
71+
func (dwp *TypeDeployWp) GetDestination() *Destination {
72+
return &dwp.Destination
7373
}
7474

7575

7676
// ////////////////////////////////////////////////////////////////////////////////
77-
// Target.Files
78-
func (dwp *TypeDeployWp) GetTargetFiles(ftype string) *FilesArray {
77+
// Destination.Files
78+
func (dwp *TypeDeployWp) GetDestinationFiles(ftype string) *FilesArray {
7979
if state := dwp.IsNil(); state.IsError() {
8080
return &FilesArray{}
8181
}
82-
return dwp.Target.GetFiles(ftype)
82+
return dwp.Destination.GetFiles(ftype)
8383
}
8484

8585

8686
// ////////////////////////////////////////////////////////////////////////////////
87-
// Target.Paths
88-
func (dwp *TypeDeployWp) GetTargetPaths() *Paths {
87+
// Destination.Paths
88+
func (dwp *TypeDeployWp) GetDestinationPaths() *Paths {
8989
if state := dwp.IsNil(); state.IsError() {
9090
return &Paths{}
9191
}
92-
return &dwp.Target.Paths
92+
return &dwp.Destination.Paths
9393
}
94-
func (dwp *TypeDeployWp) GetTargetAbsPaths() *Paths {
94+
func (dwp *TypeDeployWp) GetDestinationAbsPaths() *Paths {
9595
if state := dwp.IsNil(); state.IsError() {
9696
return &Paths{}
9797
}
98-
return &dwp.Target.AbsPaths
98+
return &dwp.Destination.AbsPaths
9999
}
100100

101101

102102
// ////////////////////////////////////////////////////////////////////////////////
103-
// Target.Revisions
104-
func (dwp *TypeDeployWp) GetTargetRevision(host string) *TargetRevision {
103+
// Destination.Revisions
104+
func (dwp *TypeDeployWp) GetDestinationRevision(host string) *Target {
105105
if state := dwp.IsNil(); state.IsError() {
106-
return &TargetRevision{}
106+
return &Target{}
107107
}
108-
return dwp.Target.GetRevisionByHost(host)
108+
return dwp.Destination.GetTargetByHost(host)
109109
}
110110

111111

112112
// ////////////////////////////////////////////////////////////////////////////////
113-
// Target.Providers
114-
func (dwp *TypeDeployWp) GetTargetProvider(provider string) *Provider {
113+
// Destination.Providers
114+
func (dwp *TypeDeployWp) GetDestinationProvider(provider string) *Provider {
115115
if state := dwp.IsNil(); state.IsError() {
116116
return &Provider{}
117117
}
118-
return dwp.Target.GetProviderByName(provider)
118+
return dwp.Destination.GetProviderByName(provider)
119119
}
120120

121121

deploywp/destination.go

Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
package deploywp
2+
3+
import (
4+
"github.com/jinzhu/copier"
5+
"github.com/newclarity/scribeHelpers/toolRuntime"
6+
"github.com/newclarity/scribeHelpers/toolTypes"
7+
"github.com/newclarity/scribeHelpers/ux"
8+
)
9+
10+
11+
const DefaultDestinationBasePath = "/tmp/deploywp"
12+
13+
type Destination struct {
14+
Files Files `json:"files"`
15+
Paths Paths `json:"paths"`
16+
Providers Providers `json:"providers"` // mapstructure:",squash"`
17+
Targets Targets `json:"targets"` // mapstructure:",squash"`
18+
19+
AbsPaths Paths
20+
AbsFiles Files
21+
22+
selectedHost *Host // Should be set to the selected host_name from arg[0]
23+
selectedHostName string // Should be set to the selected host_name from arg[0]
24+
25+
Valid bool
26+
runtime *toolRuntime.TypeRuntime
27+
state *ux.State
28+
}
29+
30+
func (d *Destination) New(runtime *toolRuntime.TypeRuntime) *Destination {
31+
runtime = runtime.EnsureNotNil()
32+
return &Destination{
33+
Files: *((*Files).New(&Files{}, runtime)),
34+
Paths: *((*Paths).New(&Paths{}, runtime)),
35+
Providers: *((*Providers).New(&Providers{}, runtime)),
36+
Targets: *((*Targets).New(&Targets{}, runtime)),
37+
AbsPaths: *((*Paths).New(&Paths{}, runtime)),
38+
AbsFiles: *((*Files).New(&Files{}, runtime)),
39+
40+
Valid: true,
41+
runtime: runtime,
42+
state: ux.NewState(runtime.CmdName, runtime.Debug),
43+
}
44+
}
45+
46+
func (d *Destination) IsNil() *ux.State {
47+
if state := ux.IfNilReturnError(d); state.IsError() {
48+
return state
49+
}
50+
d.state = d.state.EnsureNotNil()
51+
return d.state
52+
}
53+
54+
func (d *Destination) IsValid() bool {
55+
if state := ux.IfNilReturnError(d); state.IsError() {
56+
return false
57+
}
58+
for range onlyOnce {
59+
if d.Files.IsNotValid() {
60+
d.state = d.Files.state
61+
d.Valid = false
62+
break
63+
}
64+
if d.Paths.IsNotValid() {
65+
d.state = d.Paths.state
66+
d.Valid = false
67+
break
68+
}
69+
if d.Providers.IsNotValid() {
70+
//d.state = d.Providers.state
71+
d.Valid = false
72+
break
73+
}
74+
if d.Targets.IsNotValid() {
75+
//d.state = d.Revisions.state
76+
d.Valid = false
77+
break
78+
}
79+
80+
if d.AbsPaths.IsNotValid() {
81+
d.state = d.AbsPaths.state
82+
d.Valid = false
83+
break
84+
}
85+
if d.AbsFiles.IsNotValid() {
86+
d.state = d.AbsFiles.state
87+
d.Valid = false
88+
break
89+
}
90+
91+
d.Valid = true
92+
}
93+
return d.Valid
94+
}
95+
func (d *Destination) IsNotValid() bool {
96+
return !d.IsValid()
97+
}
98+
99+
func (d *Destination) Process() *ux.State {
100+
if state := d.IsNil(); state.IsError() {
101+
return state
102+
}
103+
104+
for range onlyOnce {
105+
err := copier.Copy(&d.AbsPaths, &d.Paths)
106+
d.state.SetError(err)
107+
if d.state.IsError() {
108+
break
109+
}
110+
111+
d.state = d.Providers.Process(d.runtime)
112+
if d.state.IsError() {
113+
break
114+
}
115+
116+
d.state = d.Targets.Process(d.runtime)
117+
if d.state.IsError() {
118+
break
119+
}
120+
121+
if d.Paths.BasePath == "" {
122+
d.Paths.BasePath = DefaultDestinationBasePath
123+
}
124+
//d.state = d.Paths.GetBasePath(d.Repository.GetUrlAsDir())
125+
selectedProvider := d.Providers.GetByName(d.selectedHost.Provider)
126+
d.state = d.Paths.AppendBasePath(d.selectedHost.HostName, selectedProvider.Meta.SiteName)
127+
if d.state.IsError() {
128+
break
129+
}
130+
131+
d.AbsPaths.BasePath = d.Paths.BasePath
132+
d.state = d.AbsPaths.ExpandPaths()
133+
d.state.SetError(err)
134+
if d.state.IsError() {
135+
break
136+
}
137+
138+
d.AbsFiles.Copy.Append(&d.Files.Copy)
139+
d.AbsFiles.Delete.Append(&d.Files.Delete)
140+
d.AbsFiles.Exclude.Append(&d.Files.Exclude)
141+
d.AbsFiles.Keep.Append(&d.Files.Keep)
142+
143+
d.state = d.AbsFiles.Process(d.AbsPaths)
144+
if d.state.IsError() {
145+
break
146+
}
147+
148+
d.state = d.Files.Process(d.Paths)
149+
if d.state.IsError() {
150+
break
151+
}
152+
153+
d.Valid = true
154+
}
155+
156+
return d.state
157+
}
158+
159+
160+
// ////////////////////////////////////////////////////////////////////////////////
161+
// Files
162+
func (d *Destination) GetFiles(ftype string) *FilesArray {
163+
var ret *FilesArray
164+
if state := d.IsNil(); state.IsError() {
165+
return &FilesArray{}
166+
}
167+
168+
for range onlyOnce {
169+
ret = d.Files.GetFiles(ftype)
170+
}
171+
172+
return ret
173+
}
174+
175+
176+
// ////////////////////////////////////////////////////////////////////////////////
177+
// Paths
178+
func (d *Destination) GetPaths(abs ...interface{}) *Paths {
179+
var ret *Paths
180+
if state := d.IsNil(); state.IsError() {
181+
return &Paths{}
182+
}
183+
184+
for range onlyOnce {
185+
if toolTypes.ReflectBoolArg(abs) {
186+
ret = &d.AbsPaths
187+
break
188+
}
189+
190+
ret = &d.Paths
191+
}
192+
193+
return ret
194+
}
195+
196+
197+
func (d *Destination) GetBasePath() string {
198+
if state := d.IsNil(); state.IsError() {
199+
return ""
200+
}
201+
return d.Paths.BasePath
202+
}
203+
204+
205+
// ////////////////////////////////////////////////////////////////////////////////
206+
// Providers
207+
func (d *Destination) GetProviderByName(provider string) *Provider {
208+
var ret *Provider
209+
if state := d.IsNil(); state.IsError() {
210+
return ret
211+
}
212+
return d.Providers.GetByName(provider)
213+
}
214+
func (d *Destination) GetProviderBySiteId(siteId string) *Provider {
215+
var ret *Provider
216+
if state := d.IsNil(); state.IsError() {
217+
return ret
218+
}
219+
ret = d.Providers.GetBySiteId(siteId)
220+
return ret
221+
}
222+
223+
224+
// ////////////////////////////////////////////////////////////////////////////////
225+
// Revisions
226+
func (d *Destination) GetTargetByHost(host string) *Target {
227+
var ret *Target
228+
if state := d.IsNil(); state.IsError() {
229+
return &Target{state: state}
230+
}
231+
ret = d.Targets.GetByHost(host)
232+
return ret
233+
}
234+
235+
func (d *Destination) GetTargetByName(ref string) *Target {
236+
var ret *Target
237+
if state := d.IsNil(); state.IsError() {
238+
return &Target{state: state}
239+
}
240+
ret = d.Targets.GetByRefName(ref)
241+
return ret
242+
}
243+
244+
//func (d *Destination) SelectHost(host string) *ux.State {
245+
// if state := d.IsNil(); state.IsError() {
246+
// return state
247+
// }
248+
//
249+
// for range onlyOnce {
250+
// d.selectedHost = d.GetTargetByHost(host)
251+
// d.selectedHostName = host
252+
// }
253+
//
254+
// return d.state
255+
//}
256+
257+
258+
func (d *Destination) GetSelectedHost() *Host {
259+
if state := d.IsNil(); state.IsError() {
260+
return &Host{state: state}
261+
}
262+
return d.selectedHost
263+
}
264+
265+
266+
func (d *Destination) SetDestinationHost(host *Host) *ux.State {
267+
if state := d.IsNil(); state.IsError() {
268+
return state
269+
}
270+
271+
for range onlyOnce {
272+
if host == nil {
273+
d.state.SetError("Selected host is nil.")
274+
break
275+
}
276+
277+
d.selectedHost = host
278+
d.selectedHostName = host.HostName
279+
280+
d.state.SetOk()
281+
}
282+
283+
return d.state
284+
}

0 commit comments

Comments
 (0)