Skip to content

Commit

Permalink
Make list numbering print-only
Browse files Browse the repository at this point in the history
  • Loading branch information
ahme-dev committed Jul 30, 2021
1 parent d04b97d commit 3917c2d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
19 changes: 8 additions & 11 deletions exelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
)

type exe struct {
Number int
Name string
Path string
Name string
Path string
}

// read a file with a specific (exelist) format and get the list in it
Expand All @@ -27,7 +26,7 @@ func ImportFromFile(fileName string) (retList []exe, retErr error) {
var entriesInFile = strings.Split(string(data), "\n")

// loop through the strings
for index, entryFull := range entriesInFile {
for _, entryFull := range entriesInFile {

// split each line into two parts
var entryInTwo = strings.Split(entryFull, "=>")
Expand All @@ -40,9 +39,8 @@ func ImportFromFile(fileName string) (retList []exe, retErr error) {

// append the two parts each to a field in an exe struct
var tempExe = exe{
Number: index + 1,
Name: strings.TrimSpace(entryInTwo[0]),
Path: strings.TrimSpace(entryInTwo[1]),
Name: strings.TrimSpace(entryInTwo[0]),
Path: strings.TrimSpace(entryInTwo[1]),
}

// append the exe struct to the returned list
Expand All @@ -69,7 +67,7 @@ func ImportFromScan(dirName string) (retList []exe, retErr []error) {
}

// go through dir entries
for index, dirEntry := range dirEntryList {
for _, dirEntry := range dirEntryList {

// create vars for the entry
var (
Expand Down Expand Up @@ -107,9 +105,8 @@ func ImportFromScan(dirName string) (retList []exe, retErr []error) {
// then add to list
retList = append(retList,
exe{
Number: index + 1,
Name: dirEntryNameNoSuffix,
Path: dirEntryPath,
Name: dirEntryNameNoSuffix,
Path: dirEntryPath,
},
)
}
Expand Down
20 changes: 10 additions & 10 deletions exelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func TestExportImport(t *testing.T) {
{
Description: "scan a dir and export result to a file then import back from exported file",
Expected: []exe{
{1, "flap", PathJoin(TestDir, "games/flap.exe")},
{2, "paint", PathJoin(TestDir, "ms/paint.exe")},
{3, "pt", PathJoin(TestDir, "pt.exe")},
{"flap", PathJoin(TestDir, "games/flap.exe")},
{"paint", PathJoin(TestDir, "ms/paint.exe")},
{"pt", PathJoin(TestDir, "pt.exe")},
},
ExpectedErrs: []error{},

Expand Down Expand Up @@ -120,7 +120,7 @@ func TestImportFromFile(t *testing.T) {
}{
{
Description: "import regular file",
Expected: []exe{{1, "okay", "~/Downloads/okay.exe"}},
Expected: []exe{{"okay", "~/Downloads/okay.exe"}},
ExpectedErr: nil,

ParamContent: "okay => ~/Downloads/okay.exe\n",
Expand All @@ -137,8 +137,8 @@ func TestImportFromFile(t *testing.T) {
{
Description: "multiple separators in one line in file",
Expected: []exe{
{1, "okay", "~/Downloads/okay.exe"},
{2, "yes", "~/go/bin/yes.exe"},
{"okay", "~/Downloads/okay.exe"},
{"yes", "~/go/bin/yes.exe"},
},
ExpectedErr: nil,

Expand Down Expand Up @@ -351,8 +351,8 @@ func TestExportToFile(t *testing.T) {
Perm: 0755,
},
ParamList: []exe{
{1, "ck", "~/Games/ck/ck.exe"},
{2, "fff", "~/Downloads/fff.exe"},
{"ck", "~/Games/ck/ck.exe"},
{"fff", "~/Downloads/fff.exe"},
},
},
{
Expand All @@ -365,8 +365,8 @@ func TestExportToFile(t *testing.T) {
Perm: 0755,
},
ParamList: []exe{
{1, "ck", "~/Games/ck/ck.exe"},
{2, "fff", "~/Downloads/fff.exe"},
{"ck", "~/Games/ck/ck.exe"},
{"fff", "~/Downloads/fff.exe"},
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func (r Runner) RunFromList(elementNumber int, shouldFork bool) error {
var foundTarget bool

// see if target exe is in the list
for _, exeEntry := range r.List {
if exeEntry.Number == elementNumber {
for index, exeEntry := range r.List {
if index+1 == elementNumber {
targetExe = exeEntry
foundTarget = true
break
Expand Down Expand Up @@ -192,8 +192,8 @@ func (r Runner) RunFromList(elementNumber int, shouldFork bool) error {

// return the list as a numbered string
func (r Runner) DisplayList() (ret string) {
for _, entry := range r.List {
ret += fmt.Sprintf("%v %v\n", entry.Number, entry.Name)
for index, entry := range r.List {
ret += fmt.Sprintf("%v %v\n", index+1, entry.Name)
}
return
}
6 changes: 3 additions & 3 deletions runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestRunFromList(t *testing.T) {
Program: "wine",
ProgramArgs: "",
List: []exe{
{1, "PS", PathJoin(TestDir, "PS.exe")},
{"PS", PathJoin(TestDir, "PS.exe")},
},
},
ParamRunProg: 5,
Expand Down Expand Up @@ -151,8 +151,8 @@ func TestDisplayList(t *testing.T) {
Program: "wine",
ProgramArgs: "",
List: []exe{
{1, "sr", PathJoin(TestDir, "sr.exe")},
{2, "lon", PathJoin(TestDir, "lon.exe")},
{"sr", PathJoin(TestDir, "sr.exe")},
{"lon", PathJoin(TestDir, "lon.exe")},
},
},
},
Expand Down

0 comments on commit 3917c2d

Please sign in to comment.