Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: deploytool/cmd/title.go

Issue 2182213002: deploytool: Add README.md, migrate docs to it. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Rename to "luci_deploy" Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « deploytool/cmd/staging.go ('k') | deploytool/cmd/tools.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "path/filepath"
9 "unicode"
10
11 "github.com/luci/luci-go/common/errors"
12 )
13
14 type title string
15
16 func (t title) validate() error {
17 if len(t) == 0 {
18 return errors.New("cannot be empty")
19 }
20
21 idx := 0
22 for _, r := range t {
23 if !(unicode.IsLetter(r) || unicode.IsNumber(r) || r == '-') {
24 return errors.Reason("character at %(pos)d (%(char)c) is not permitted in a title").
25 D("pos", idx).D("char", r).Err()
26 }
27 idx++
28 }
29 return nil
30 }
31
32 // titleFromConfigPath returns the title of a configuration item identified by
33 // the specified configuration file.
34 //
35 // If the file was not a valid config path, or the title was not valid, an error
36 // will be returned.
37 func titleFromConfigPath(path string) (title, error) {
38 path = filepath.Base(path)
39 if filepath.Ext(path) == configExt {
40 t := title(path[:len(path)-len(configExt)])
41 if err := t.validate(); err != nil {
42 return "", err
43 }
44 return t, nil
45 }
46 return "", errors.Reason("missing config extension [" + configExt + "]") .Err()
47 }
OLDNEW
« no previous file with comments | « deploytool/cmd/staging.go ('k') | deploytool/cmd/tools.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698