1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENSE file for details.
11
// ParseAliasFile will read the specified file and convert
12
// the content to a map of names to the command line arguments
13
// they relate to. The function will always return a valid map, even
15
func ParseAliasFile(aliasFilename string) map[string][]string {
16
result := map[string][]string{}
17
if aliasFilename == "" {
21
content, err := ioutil.ReadFile(aliasFilename)
23
logger.Tracef("unable to read alias file %q: %s", aliasFilename, err)
27
lines := strings.Split(string(content), "\n")
28
for i, line := range lines {
29
line = strings.TrimSpace(line)
30
if line == "" || strings.HasPrefix(line, "#") {
31
// skip blank lines and comments
34
parts := strings.SplitN(line, "=", 2)
36
logger.Warningf("line %d bad in alias file: %s", i+1, line)
39
name, value := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
41
logger.Warningf("line %d missing alias name in alias file: %s", i+1, line)
45
logger.Warningf("line %d missing alias value in alias file: %s", i+1, line)
49
logger.Tracef("setting alias %q=%q", name, value)
50
result[name] = strings.Fields(value)