Skip to content

Commit 05ab015

Browse files
committed
add: add sna cmd handling
1 parent 9017d8d commit 05ab015

5 files changed

Lines changed: 264 additions & 200 deletions

File tree

cli/action/dsk.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ type DskDescriptor struct {
3636

3737
func NewDskDescriptor() *DskDescriptor {
3838
return &DskDescriptor{
39-
Sector: 9,
40-
Track: 39,
41-
Head: 2,
42-
Type: dsk.DataFormat,
39+
Sector: 9,
40+
Track: 39,
41+
Head: 2,
42+
Type: dsk.DataFormat,
43+
FolderPath: "./",
4344
}
4445
}
4546

@@ -111,6 +112,15 @@ func (a *AmsdosFileDescriptor) WithPath(path string) *AmsdosFileDescriptor {
111112
return a
112113
}
113114

115+
func (a *AmsdosFileDescriptor) WithPaths(s ...string) *AmsdosFileDescriptor {
116+
for _, v := range s {
117+
if v != "" {
118+
a.Path = v
119+
}
120+
}
121+
return a
122+
}
123+
114124
func (a *AmsdosFileDescriptor) AddExec(exec string) *AmsdosFileDescriptor {
115125
if exec != "" {
116126
value, err := utils.ParseHex16(exec)
@@ -145,11 +155,11 @@ type Action struct {
145155
options Options
146156
desc DskDescriptor
147157
fd AmsdosFileDescriptor
148-
actions *DskActions
158+
actions *DskTasks
149159
}
150160

151161
func (a Action) DskIsSet() bool {
152-
return strings.Contains(strings.ToLower(a.Path), ".dsk")
162+
return a.Path != ""
153163
}
154164

155165
func (a *Action) WithOptions(options Options) *Action {
@@ -167,14 +177,21 @@ func (a *Action) WithAmsdosFileDescriptor(fd AmsdosFileDescriptor) *Action {
167177
return a
168178
}
169179

170-
func NewAction(dskPath string) *Action {
180+
func NewAction(paths ...string) *Action {
181+
var path string
182+
for _, v := range paths {
183+
if v != "" {
184+
path = v
185+
break
186+
}
187+
}
171188
return &Action{
172-
Path: dskPath,
173-
actions: NewDskActions(),
189+
Path: path,
190+
actions: NewDskTasks(),
174191
}
175192
}
176193

177-
func (a *Action) WithDskActions(actions *DskActions) *Action {
194+
func (a *Action) WithDskActions(actions *DskTasks) *Action {
178195
a.actions = actions
179196
return a
180197
}
@@ -209,7 +226,7 @@ func (a *Action) DoDskActions() (onError bool, message, hint string) {
209226
case ActionRawImportDsk:
210227
onError, message, hint = RawImportDsk(a.d, a.fd.Path, a.desc, a.options.quiet)
211228
case ActionGetAllFileDsk:
212-
onError, message, hint = GetAllFileDsk(a.d, a.desc, a.options)
229+
onError, message, hint = GetAllFileDsk(action.Folder, a.desc, a.options)
213230
case ActionListDsk:
214231
onError, message, hint = ListDsk(a.d, a.Path)
215232
default:
@@ -311,16 +328,16 @@ func (a *Action) DoFileActions() (onError bool, message, hint string) {
311328
return false, "", ""
312329
}
313330

314-
func GetAllFileDsk(d dsk.DSK, desc DskDescriptor, opts Options) (onError bool, message, hint string) {
315-
files, err := fs.ReadDir(os.DirFS("/"), desc.FolderPath)
331+
func GetAllFileDsk(folder string, desc DskDescriptor, opts Options) (onError bool, message, hint string) {
332+
files, err := fs.ReadDir(os.DirFS("/"), folder)
316333
if err != nil {
317334
msg.ExitOnError(err.Error(), "Please check your folder path")
318335
}
319336
for _, file := range files {
320337
if !file.IsDir() {
321338
if strings.ToUpper(path.Ext(file.Name())) == ".DSK" {
322-
dskfolderPath := desc.FolderPath + string(filepath.Separator) + strings.Replace(file.Name(), path.Ext(file.Name()), "", -1)
323-
dskFilepath := desc.FolderPath + string(filepath.Separator) + file.Name()
339+
dskfolderPath := folder + string(filepath.Separator) + strings.Replace(file.Name(), path.Ext(file.Name()), "", -1)
340+
dskFilepath := folder + string(filepath.Separator) + file.Name()
324341
err = os.Mkdir(dskfolderPath, os.ModePerm)
325342
if err != nil && !errors.Is(err, os.ErrExist) {
326343
msg.ExitOnError(err.Error(), "Please check your folder path")

cli/action/dsk_action.go

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,123 @@
11
package action
22

3-
type DskAction string
3+
type DskTask string
44

55
var (
6-
ActionListDsk DskAction = "list"
7-
ActionFormatDsk DskAction = "format"
8-
ActionDisplayHexaFileDsk DskAction = "hexa"
9-
ActionDesassembleFileDsk DskAction = "desassemble"
10-
ActionListBasic DskAction = "listbasic"
11-
ActionAnalyseDsk DskAction = "analyze"
12-
ActionPutFileDsk DskAction = "put"
13-
ActionRemoveFileDsk DskAction = "remove"
14-
ActionGetFileDsk DskAction = "get"
15-
ActionGetAllFileDsk DskAction = "getall"
16-
ActionAsciiFileDsk DskAction = "ascii"
17-
ActionRawExportDsk DskAction = "rawexport"
18-
ActionRawImportDsk DskAction = "rawimport"
19-
ActionFileinfoDsk DskAction = "info"
6+
ActionListDsk DskTask = "list"
7+
ActionFormatDsk DskTask = "format"
8+
ActionDisplayHexaFileDsk DskTask = "hexa"
9+
ActionDesassembleFileDsk DskTask = "desassemble"
10+
ActionListBasic DskTask = "listbasic"
11+
ActionAnalyseDsk DskTask = "analyze"
12+
ActionPutFileDsk DskTask = "put"
13+
ActionRemoveFileDsk DskTask = "remove"
14+
ActionGetFileDsk DskTask = "get"
15+
ActionGetAllFileDsk DskTask = "getall"
16+
ActionAsciiFileDsk DskTask = "ascii"
17+
ActionRawExportDsk DskTask = "rawexport"
18+
ActionRawImportDsk DskTask = "rawimport"
19+
ActionFileinfoDsk DskTask = "info"
2020
)
2121

22-
type DskActionFile struct {
23-
File string
24-
a DskAction
22+
type DskTaskFile struct {
23+
File string
24+
Folder string
25+
a DskTask
2526
}
2627

27-
type DskActions struct {
28-
a []DskActionFile
28+
type DskTasks struct {
29+
a []DskTaskFile
2930
}
3031

31-
func NewDskActions() *DskActions {
32-
return &DskActions{
33-
a: []DskActionFile{},
32+
func NewDskTasks() *DskTasks {
33+
return &DskTasks{
34+
a: []DskTaskFile{},
3435
}
3536
}
3637

37-
func (a *DskActions) WithActionListDsk(path string, isSet bool) *DskActions {
38+
func (a *DskTasks) WithActionListDsk(path string, isSet bool) *DskTasks {
3839
if isSet {
39-
a.a = append(a.a, DskActionFile{File: path, a: ActionListDsk})
40+
a.a = append(a.a, DskTaskFile{File: path, a: ActionListDsk})
4041
}
4142
return a
4243
}
4344

44-
func (a *DskActions) WithActionFormatDsk(path string, isSet bool) *DskActions {
45+
func (a *DskTasks) WithActionFormatDsk(path string, isSet bool) *DskTasks {
4546
if isSet {
46-
a.a = append(a.a, DskActionFile{File: path, a: ActionFormatDsk})
47+
a.a = append(a.a, DskTaskFile{File: path, a: ActionFormatDsk})
4748
}
4849
return a
4950
}
50-
func (a *DskActions) WithActionDisplayHexaFileDsk(path string, isSet bool) *DskActions {
51+
func (a *DskTasks) WithActionDisplayHexaFileDsk(path string, isSet bool) *DskTasks {
5152
if isSet {
52-
a.a = append(a.a, DskActionFile{File: path, a: ActionDisplayHexaFileDsk})
53+
a.a = append(a.a, DskTaskFile{File: path, a: ActionDisplayHexaFileDsk})
5354
}
5455
return a
5556
}
56-
func (a *DskActions) WithActionDesassembleFileDsk(path string, isSet bool) *DskActions {
57+
func (a *DskTasks) WithActionDesassembleFileDsk(path string, isSet bool) *DskTasks {
5758
if isSet {
58-
a.a = append(a.a, DskActionFile{File: path, a: ActionDesassembleFileDsk})
59+
a.a = append(a.a, DskTaskFile{File: path, a: ActionDesassembleFileDsk})
5960
}
6061
return a
6162
}
62-
func (a *DskActions) WithActionListBasic(path string, isSet bool) *DskActions {
63+
func (a *DskTasks) WithActionListBasic(path string, isSet bool) *DskTasks {
6364
if isSet {
64-
a.a = append(a.a, DskActionFile{File: path, a: ActionListBasic})
65+
a.a = append(a.a, DskTaskFile{File: path, a: ActionListBasic})
6566
}
6667
return a
6768
}
68-
func (a *DskActions) WithActionAnalyseDsk(path string, isSet bool) *DskActions {
69+
func (a *DskTasks) WithActionAnalyseDsk(path string, isSet bool) *DskTasks {
6970
if isSet {
70-
a.a = append(a.a, DskActionFile{File: path, a: ActionAnalyseDsk})
71+
a.a = append(a.a, DskTaskFile{File: path, a: ActionAnalyseDsk})
7172
}
7273
return a
7374
}
74-
func (a *DskActions) WithActionPutFileDsk(path string, isSet bool) *DskActions {
75+
func (a *DskTasks) WithActionPutFileDsk(path string, isSet bool) *DskTasks {
7576
if isSet {
76-
a.a = append(a.a, DskActionFile{File: path, a: ActionPutFileDsk})
77+
a.a = append(a.a, DskTaskFile{File: path, a: ActionPutFileDsk})
7778
}
7879
return a
7980
}
80-
func (a *DskActions) WithActionRemoveFileDsk(path string, isSet bool) *DskActions {
81+
func (a *DskTasks) WithActionRemoveFileDsk(path string, isSet bool) *DskTasks {
8182
if isSet {
82-
a.a = append(a.a, DskActionFile{File: path, a: ActionRemoveFileDsk})
83+
a.a = append(a.a, DskTaskFile{File: path, a: ActionRemoveFileDsk})
8384
}
8485
return a
8586
}
86-
func (a *DskActions) WithActionGetFileDsk(path string, isSet bool) *DskActions {
87+
func (a *DskTasks) WithActionGetFileDsk(path string, isSet bool) *DskTasks {
8788
if isSet {
88-
a.a = append(a.a, DskActionFile{File: path, a: ActionGetFileDsk})
89+
a.a = append(a.a, DskTaskFile{File: path, a: ActionGetFileDsk})
8990
}
9091
return a
9192
}
92-
func (a *DskActions) WithActionAsciiFileDsk(path string, isSet bool) *DskActions {
93+
func (a *DskTasks) WithActionAsciiFileDsk(path string, isSet bool) *DskTasks {
9394
if isSet {
94-
a.a = append(a.a, DskActionFile{File: path, a: ActionAsciiFileDsk})
95+
a.a = append(a.a, DskTaskFile{File: path, a: ActionAsciiFileDsk})
9596
}
9697
return a
9798
}
98-
func (a *DskActions) WithActionRawExportDsk(path string, isSet bool) *DskActions {
99+
func (a *DskTasks) WithActionRawExportDsk(path string, isSet bool) *DskTasks {
99100
if isSet {
100-
a.a = append(a.a, DskActionFile{File: path, a: ActionRawExportDsk})
101+
a.a = append(a.a, DskTaskFile{File: path, a: ActionRawExportDsk})
101102
}
102103
return a
103104
}
104-
func (a *DskActions) WithActionRawImportDsk(path string, isSet bool) *DskActions {
105+
func (a *DskTasks) WithActionRawImportDsk(path string, isSet bool) *DskTasks {
105106
if isSet {
106-
a.a = append(a.a, DskActionFile{File: path, a: ActionRawImportDsk})
107+
a.a = append(a.a, DskTaskFile{File: path, a: ActionRawImportDsk})
107108
}
108109
return a
109110
}
110-
func (a *DskActions) WithActionFileinfoDsk(path string, isSet bool) *DskActions {
111+
func (a *DskTasks) WithActionFileinfoDsk(path string, isSet bool) *DskTasks {
111112
if isSet {
112-
a.a = append(a.a, DskActionFile{File: path, a: ActionFileinfoDsk})
113+
a.a = append(a.a, DskTaskFile{File: path, a: ActionFileinfoDsk})
113114
}
114115
return a
115116
}
116117

117-
func (a *DskActions) WithActionGetAllFileDsk(path string, isSet bool) *DskActions {
118+
func (a *DskTasks) WithActionGetAllFileDsk(path string, isSet bool) *DskTasks {
118119
if isSet {
119-
a.a = append(a.a, DskActionFile{File: path, a: ActionGetAllFileDsk})
120+
a.a = append(a.a, DskTaskFile{Folder: path, File: path, a: ActionGetAllFileDsk})
120121
}
121122
return a
122123
}

0 commit comments

Comments
 (0)