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

package main

import (
	"github.com/urfave/cli"
	"net/url"
	"strings"
)

// ByAlphabet is for sorting
type ByAlphabet []cli.Command

func (a ByAlphabet) Len() int           { return len(a) }
func (a ByAlphabet) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByAlphabet) Less(i, j int) bool { return a[i].Name < a[j].Name }

func filterURL(in string) (out string) {
	uri, err := url.Parse(in)
	if err != nil {
		out = ""
	} else {
		uri := url.URL{Scheme: uri.Scheme, Host: uri.Host}
		out = uri.String()
	}
	return
}

func basename(in string) (out string) {
	uri, err := url.Parse(in)
	if err != nil {
		out = ""
	} else {
		// Remove the :NN part of present
		out = strings.Split(uri.Host, ":")[0]
	}
	return
}