hancock

Check-in [edf65bff1c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:cmd/hancock: fix support for relative file URLs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: edf65bff1c6beeb80d16abbc3f96751e8ca7fc66492fb1a8c8defb2ed2ccd9a8
User & Date: dnc 2020-01-09 19:36:28
Context
2020-01-09
19:37
cmd/hancock: updates to generated documentation check-in: 45ed13f554 user: dnc tags: trunk
19:36
cmd/hancock: fix support for relative file URLs check-in: edf65bff1c user: dnc tags: trunk
19:35
cmd/hancock: minor fixes; cleanup check-in: e17191b0d8 user: dnc tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to cmd/hancock/hancock.go.

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
131
132
133
134
135
136
137





138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
		Description: `Create and inspect Hancock Protocol activity.`,
	})

	_, err := command.Config()
	if errors.Cause(err) == config.ConfigNotFound {
		// not a problem, we'll use defaults
		// TODO(dnc): if -config specified explicitly on command line, make this a fatal error
		command.Info(err)
		err = nil
	}
	command.CheckUsage(err)

	// this command requires an operation
	if len(flag.CommandLine.Args()) < 1 {
		command.CheckUsage(errors.New("command requires an operation"))
................................................................................
	u, err := url.Parse(flag)
	if err != nil {
		return nil, err
	}

	switch u.Scheme {
	case "file":





		fi, err := os.Stat(u.Path)
		if err != nil {
			return nil, err
		}
		switch mode := fi.Mode(); {
		case mode.IsDir():
			s = store.NewFileStore(u.Path)
		case mode.IsRegular():
			db, err := bolt.Open(u.Path, 0600, nil)
			if err != nil {
				return nil, err
			}
			s, err = boltstore.NewBoltStore(db)
			if err != nil {
				return nil, err
			}
		}

	case "http":
		s = &httpclient{url: *u}

	default:
		return nil, fmt.Errorf("unexpected store sheme (%q)", u.Scheme)
	}
	stor[flag] = s
	return s, nil







|







 







>
>
>
>
>
|





|

|









|







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
		Description: `Create and inspect Hancock Protocol activity.`,
	})

	_, err := command.Config()
	if errors.Cause(err) == config.ConfigNotFound {
		// not a problem, we'll use defaults
		// TODO(dnc): if -config specified explicitly on command line, make this a fatal error
		command.V(1).Info(err)
		err = nil
	}
	command.CheckUsage(err)

	// this command requires an operation
	if len(flag.CommandLine.Args()) < 1 {
		command.CheckUsage(errors.New("command requires an operation"))
................................................................................
	u, err := url.Parse(flag)
	if err != nil {
		return nil, err
	}

	switch u.Scheme {
	case "file":
		p := u.Path
		if p == "" {
			// i.e. file:./relative/path
			p = u.Opaque
		}
		fi, err := os.Stat(p)
		if err != nil {
			return nil, err
		}
		switch mode := fi.Mode(); {
		case mode.IsDir():
			s = store.NewFileStore(p)
		case mode.IsRegular():
			db, err := bolt.Open(p, 0600, nil)
			if err != nil {
				return nil, err
			}
			s, err = boltstore.NewBoltStore(db)
			if err != nil {
				return nil, err
			}
		}

	case "http", "https":
		s = &httpclient{url: *u}

	default:
		return nil, fmt.Errorf("unexpected store sheme (%q)", u.Scheme)
	}
	stor[flag] = s
	return s, nil