cmd/gondole-cli/utils.go
author Mikael Berthe <mikael@lilotux.net>
Sun, 16 Apr 2017 02:12:38 +0200
changeset 127 96a7f2432d27
parent 83 adc39ae774c0
permissions -rw-r--r--
GetTimelines: Allow '#' as hashtag prefix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
     1
package main
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
     2
72
e2eabbf63c82 Add basename & filterURL.
Ollivier Robert <roberto@keltia.net>
parents: 53
diff changeset
     3
import (
83
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
     4
	"github.com/urfave/cli"
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
     5
	"net/url"
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
     6
	"strings"
72
e2eabbf63c82 Add basename & filterURL.
Ollivier Robert <roberto@keltia.net>
parents: 53
diff changeset
     7
)
41
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
     8
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
     9
// ByAlphabet is for sorting
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    10
type ByAlphabet []cli.Command
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    11
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    12
func (a ByAlphabet) Len() int           { return len(a) }
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    13
func (a ByAlphabet) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    14
func (a ByAlphabet) Less(i, j int) bool { return a[i].Name < a[j].Name }
79be65ec4afd Add sorting for the future commands.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    15
72
e2eabbf63c82 Add basename & filterURL.
Ollivier Robert <roberto@keltia.net>
parents: 53
diff changeset
    16
func filterURL(in string) (out string) {
83
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    17
	uri, err := url.Parse(in)
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    18
	if err != nil {
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    19
		out = ""
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    20
	} else {
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    21
		uri := url.URL{Scheme: uri.Scheme, Host: uri.Host}
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    22
		out = uri.String()
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    23
	}
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    24
	return
72
e2eabbf63c82 Add basename & filterURL.
Ollivier Robert <roberto@keltia.net>
parents: 53
diff changeset
    25
}
e2eabbf63c82 Add basename & filterURL.
Ollivier Robert <roberto@keltia.net>
parents: 53
diff changeset
    26
e2eabbf63c82 Add basename & filterURL.
Ollivier Robert <roberto@keltia.net>
parents: 53
diff changeset
    27
func basename(in string) (out string) {
83
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    28
	uri, err := url.Parse(in)
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    29
	if err != nil {
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    30
		out = ""
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    31
	} else {
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    32
		// Remove the :NN part of present
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    33
		out = strings.Split(uri.Host, ":")[0]
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    34
	}
adc39ae774c0 Make it work with non-defaut instances
Mikael Berthe <mikael@lilotux.net>
parents: 75
diff changeset
    35
	return
72
e2eabbf63c82 Add basename & filterURL.
Ollivier Robert <roberto@keltia.net>
parents: 53
diff changeset
    36
}