@@ -68,6 +68,7 @@ pub struct ProgressBar {
68
68
}
69
69
70
70
impl ProgressBar {
71
+
71
72
/// Create a `ProgressBar` object to update progress
72
73
///
73
74
/// # Arguments
@@ -102,6 +103,12 @@ impl ProgressBar {
102
103
} )
103
104
}
104
105
106
+ /// Increment the progress bar by the specified amount and write the progress
107
+ ///
108
+ /// # Arguments
109
+ ///
110
+ /// * `delta` - The amount to increment the progress bar by
111
+ ///
105
112
pub fn increment ( & mut self , delta : u64 ) {
106
113
if self . format == ProgressFormat :: None {
107
114
return ;
@@ -124,12 +131,26 @@ impl ProgressBar {
124
131
}
125
132
}
126
133
134
+ /// Set the resource being operated on and write the progress
135
+ ///
136
+ /// # Arguments
137
+ ///
138
+ /// * `name` - The name of the resource being operated on
139
+ /// * `resource_type` - The type of the resource being operated on
140
+ /// * `result` - The result of the operation
141
+ ///
127
142
pub fn set_resource ( & mut self , name : & str , resource_type : & str , result : Option < & Value > ) {
128
143
self . progress_value . resource_name = Some ( name. to_string ( ) ) ;
129
144
self . progress_value . resource_type = Some ( resource_type. to_string ( ) ) ;
130
145
self . progress_value . result = result. cloned ( ) ;
131
146
}
132
147
148
+ /// Set the status of the operation and write the progress
149
+ ///
150
+ /// # Arguments
151
+ ///
152
+ /// * `status` - The status of the operation
153
+ ///
133
154
pub fn set_activity ( & mut self , activity : & str ) {
134
155
match self . format {
135
156
ProgressFormat :: Json => {
@@ -143,17 +164,17 @@ impl ProgressBar {
143
164
}
144
165
}
145
166
167
+ /// Set the number of total items to complete
168
+ ///
169
+ /// # Arguments
170
+ ///
171
+ /// * `len` - The number of total items to complete
172
+ ///
146
173
pub fn set_length ( & mut self , len : u64 ) {
147
174
match self . format {
148
175
ProgressFormat :: Json => {
149
176
self . item_count = len;
150
- if self . item_count > 0 {
151
- self . progress_value . percent_complete = if self . item_position >= self . item_count {
152
- 100
153
- } else {
154
- u8:: try_from ( ( self . item_position * 100 ) / self . item_count ) . unwrap_or ( 100 )
155
- } ;
156
- }
177
+ self . set_percent_complete ( ) ;
157
178
} ,
158
179
ProgressFormat :: Default => {
159
180
self . console_bar . pb_set_length ( len) ;
@@ -162,18 +183,18 @@ impl ProgressBar {
162
183
}
163
184
}
164
185
186
+ /// Set the position as progress through the items and write the progress
187
+ ///
188
+ /// # Arguments
189
+ ///
190
+ /// * `pos` - The position as progress through the items
191
+ ///
165
192
pub fn set_position ( & mut self , pos : u64 ) {
166
193
match self . format {
167
194
ProgressFormat :: Json => {
168
195
self . item_position = pos;
169
- if self . item_count > 0 {
170
- self . progress_value . percent_complete = if self . item_position >= self . item_count {
171
- 100
172
- } else {
173
- u8:: try_from ( ( self . item_position * 100 ) / self . item_count ) . unwrap_or ( 100 )
174
- } ;
175
- self . write_json ( ) ;
176
- }
196
+ self . set_percent_complete ( ) ;
197
+ self . write_json ( ) ;
177
198
} ,
178
199
ProgressFormat :: Default => {
179
200
self . console_bar . pb_set_position ( pos) ;
@@ -189,4 +210,14 @@ impl ProgressBar {
189
210
trace ! ( "{}" , t!( "progress.failedToSerialize" , json = self . progress_value : { : ?} ) ) ;
190
211
}
191
212
}
213
+
214
+ fn set_percent_complete ( & mut self ) {
215
+ if self . item_count > 0 {
216
+ self . progress_value . percent_complete = if self . item_position >= self . item_count {
217
+ 100
218
+ } else {
219
+ u8:: try_from ( ( self . item_position * 100 ) / self . item_count ) . unwrap_or ( 100 )
220
+ } ;
221
+ }
222
+ }
192
223
}
0 commit comments