|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type helpMs struct {
|
|
|
|
flag string
|
|
|
|
shortenFlag string
|
|
|
|
handler string
|
|
|
|
}
|
|
|
|
|
|
|
|
func obtainValues(value, strsplit string) string {
|
|
|
|
values := strings.Split(value, "=")
|
|
|
|
return values[len(values)-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
func setMs(flag, shortenFlag, handler string) *helpMs {
|
|
|
|
helpMs := &helpMs{
|
|
|
|
flag: flag,
|
|
|
|
shortenFlag: shortenFlag,
|
|
|
|
handler: handler,
|
|
|
|
}
|
|
|
|
return helpMs
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
size := len(os.Args)
|
|
|
|
|
|
|
|
if size == 1 || os.Args[1] == "-h" || os.Args[1] == "--help" {
|
|
|
|
table := []helpMs{}
|
|
|
|
|
|
|
|
helpMs := setMs("--insert", "-i", "This flag inserts the string into the string passed as argument.")
|
|
|
|
table = append(table, *helpMs)
|
|
|
|
helpMs = setMs("--order", "-o", "This flag will behave like a boolean, if it is called it will order the argument.")
|
|
|
|
table = append(table, *helpMs)
|
|
|
|
|
|
|
|
for _, v := range table {
|
|
|
|
fmt.Println(v.flag)
|
|
|
|
fmt.Println(" ", v.shortenFlag)
|
|
|
|
fmt.Println(" ", v.handler)
|
|
|
|
}
|
|
|
|
} else if size <= 4 {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
var runes []rune
|
|
|
|
strToInsert := ""
|
|
|
|
var order bool
|
|
|
|
|
|
|
|
for i := 1; i < size; i++ {
|
|
|
|
if strings.Contains(os.Args[i], "--insert") || strings.Contains(os.Args[i], "-i") {
|
|
|
|
strToInsert = obtainValues(os.Args[i], "=")
|
|
|
|
} else if strings.Contains(os.Args[i], "--order") || strings.Contains(os.Args[i], "-o") {
|
|
|
|
order = true
|
|
|
|
} else {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
runes = []rune(os.Args[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if strToInsert != "" {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
concatStr := string(runes) + strToInsert
|
|
|
|
runes = []rune(concatStr)
|
|
|
|
}
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
if order {
|
|
|
|
sort.Slice(runes, func(i, j int) bool {
|
|
|
|
return runes[i] < runes[j]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
fmt.Println(string(runes))
|
|
|
|
}
|
|
|
|
}
|