@@ -2,7 +2,7 @@ package ishell
2
2
3
3
// Context is an ishell context. It embeds ishell.Actions.
4
4
type Context struct {
5
- values map [ string ] interface {}
5
+ contextValues
6
6
progressBar ProgressBar
7
7
err error
8
8
@@ -24,35 +24,38 @@ func (c *Context) Err(err error) {
24
24
c .err = err
25
25
}
26
26
27
+ // ProgressBar returns the progress bar for the current shell context.
28
+ func (c * Context ) ProgressBar () ProgressBar {
29
+ return c .progressBar
30
+ }
31
+
32
+ // contextValues is the map for values in the context.
33
+ type contextValues map [string ]interface {}
34
+
27
35
// Get returns the value associated with this context for key, or nil
28
36
// if no value is associated with key. Successive calls to Get with
29
37
// the same key returns the same result.
30
- func (c * Context ) Get (key string ) interface {} {
31
- return c . values [key ]
38
+ func (c contextValues ) Get (key string ) interface {} {
39
+ return c [key ]
32
40
}
33
41
34
42
// Set sets the key in this context to value.
35
- func (c * Context ) Set (key string , value interface {}) {
36
- if c . values == nil {
37
- c . values = make (map [string ]interface {})
43
+ func (c * contextValues ) Set (key string , value interface {}) {
44
+ if * c == nil {
45
+ * c = make (map [string ]interface {})
38
46
}
39
- c . values [key ] = value
47
+ ( * c ) [key ] = value
40
48
}
41
49
42
50
// Del deletes key and its value in this context.
43
- func (c * Context ) Del (key string ) {
44
- delete (c . values , key )
51
+ func (c contextValues ) Del (key string ) {
52
+ delete (c , key )
45
53
}
46
54
47
55
// Keys returns all keys in the context.
48
- func (c * Context ) Keys () (keys []string ) {
49
- for key := range c . values {
56
+ func (c contextValues ) Keys () (keys []string ) {
57
+ for key := range c {
50
58
keys = append (keys , key )
51
59
}
52
60
return
53
61
}
54
-
55
- // ProgressBar returns the progress bar for the current shell context.
56
- func (c * Context ) ProgressBar () ProgressBar {
57
- return c .progressBar
58
- }
0 commit comments