mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.6 KiB
73 lines
1.6 KiB
5 years ago
|
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 {
|
||
5 years ago
|
var runes []rune
|
||
5 years ago
|
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 {
|
||
5 years ago
|
runes = []rune(os.Args[i])
|
||
5 years ago
|
}
|
||
|
}
|
||
|
if strToInsert != "" {
|
||
5 years ago
|
concatStr := string(runes) + strToInsert
|
||
|
runes = []rune(concatStr)
|
||
5 years ago
|
}
|
||
5 years ago
|
if order {
|
||
|
sort.Slice(runes, func(i, j int) bool {
|
||
|
return runes[i] < runes[j]
|
||
|
})
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
fmt.Println(string(runes))
|
||
5 years ago
|
}
|
||
|
}
|