| 1 | package commands |
| 2 | |
| 3 | import ( |
| 4 | cmds "github.com/ipfs/go-ipfs-cmds" |
| 5 | ) |
| 6 | |
| 7 | func CreateCmdExtras(opts ...func(e *cmds.Extra)) *cmds.Extra { |
| 8 | e := new(cmds.Extra) |
| 9 | for _, o := range opts { |
| 10 | o(e) |
| 11 | } |
| 12 | return e |
| 13 | } |
| 14 | |
| 15 | type doesNotUseRepo struct{} |
| 16 | |
| 17 | func SetDoesNotUseRepo(val bool) func(e *cmds.Extra) { |
| 18 | return func(e *cmds.Extra) { |
| 19 | e.SetValue(doesNotUseRepo{}, val) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | func GetDoesNotUseRepo(e *cmds.Extra) (val bool, found bool) { |
| 24 | return getBoolFlag(e, doesNotUseRepo{}) |
| 25 | } |
| 26 | |
| 27 | // doesNotUseConfigAsInput describes commands that do not use the config as |
| 28 | // input. These commands either initialize the config or perform operations |
| 29 | // that don't require access to the config. |
| 30 | // |
| 31 | // pre-command hooks that require configs must not be run before these |
| 32 | // commands. |
| 33 | type doesNotUseConfigAsInput struct{} |
| 34 | |
| 35 | func SetDoesNotUseConfigAsInput(val bool) func(e *cmds.Extra) { |
| 36 | return func(e *cmds.Extra) { |
| 37 | e.SetValue(doesNotUseConfigAsInput{}, val) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func GetDoesNotUseConfigAsInput(e *cmds.Extra) (val bool, found bool) { |
| 42 | return getBoolFlag(e, doesNotUseConfigAsInput{}) |
| 43 | } |
| 44 | |
| 45 | // preemptsAutoUpdate describes commands that must be executed without the |
| 46 | // auto-update pre-command hook |
| 47 | type preemptsAutoUpdate struct{} |
| 48 | |
| 49 | func SetPreemptsAutoUpdate(val bool) func(e *cmds.Extra) { |
| 50 | return func(e *cmds.Extra) { |
| 51 | e.SetValue(preemptsAutoUpdate{}, val) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func GetPreemptsAutoUpdate(e *cmds.Extra) (val bool, found bool) { |
| 56 | return getBoolFlag(e, preemptsAutoUpdate{}) |
| 57 | } |
| 58 | |
| 59 | func getBoolFlag(e *cmds.Extra, key any) (val bool, found bool) { |
| 60 | var ival any |
| 61 | ival, found = e.GetValue(key) |
| 62 | if !found { |
| 63 | return false, false |
| 64 | } |
| 65 | val = ival.(bool) |
| 66 | return val, found |
| 67 | } |