This question already has an answer here:
I have code which execute npm install as below:
cmd := exec.Command("npm", "install")
and it finish with
if err = cmd.Wait(); err != nil {
logs.("Error running %s: %v
", cp[1:], err)
return err
}
I want to use progress bar and I've found the following https://github.com/cheggaaa/pb but since I dont control the time of the execution ( I dont know when it finish), how can I use it ?
UPDATE
Since we cannot calculate the time that will take (it depends on network etc) so I just want to show that something is working, show that the process is running ,since the user wait 20 sec and he think that nothing working, how it can be done?
</div>
The very short answer is: you can't if you don't have any indicative units.
The slightly longer answer: Providing feedback to the user can be done in several ways. If you don't have granular progress information (E.g.: n out of 10 steps has been completed or n out of 10 seconds have passed), you can't really show a meaningful progress bar.
You can provide the user with feedback about what's happening. This is, however, something npm already does so why not just show that output instead?
If you only care about showing a progress bar regardless of how meaningful it might be, what you could do is guesstimate how much time the process is going to take. Simply time it once and use that as a point of reference.