@@ -2,7 +2,7 @@ package ishell
22
33// Context is an ishell context. It embeds ishell.Actions.
44type Context struct {
5- values map [ string ] interface {}
5+ contextValues
66 progressBar ProgressBar
77 err error
88
@@ -24,35 +24,38 @@ func (c *Context) Err(err error) {
2424 c .err = err
2525}
2626
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+
2735// Get returns the value associated with this context for key, or nil
2836// if no value is associated with key. Successive calls to Get with
2937// 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 ]
3240}
3341
3442// 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 {})
3846 }
39- c . values [key ] = value
47+ ( * c ) [key ] = value
4048}
4149
4250// 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 )
4553}
4654
4755// 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 {
5058 keys = append (keys , key )
5159 }
5260 return
5361}
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