Skip to content

Commit 00dcb7e

Browse files
committed
adds force flag
1 parent 21c66c9 commit 00dcb7e

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/go_over.gleam

+20-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,35 @@ import gleam/list
44
import gleam/option
55
import gleam/string
66
import go_over/advisories
7+
import go_over/constants
78
import go_over/packages
89
import go_over/retired
910
import go_over/warning
1011
import go_over/yaml
1112
import shellout
13+
import simplifile
1214

1315
pub fn main() {
1416
let assert Ok(_) = yaml.start()
1517
let args = shellout.arguments()
1618
let skip = list.any(args, fn(arg) { arg == "--skip" })
19+
let force = list.any(args, fn(arg) { arg == "--force" })
1720
let pkgs = packages.read_manifest("./manifest.toml")
1821

22+
case force && skip {
23+
True -> {
24+
shellout.style("Cannot specify both `--skip` & `--force`", with: shellout.color(["red"]), custom: [])
25+
|> io.print
26+
shellout.exit(1)
27+
}
28+
_ -> Nil
29+
}
30+
31+
let _ = case force {
32+
True -> simplifile.delete(constants.go_over_path())
33+
_ -> Ok(Nil)
34+
}
35+
1936
let vulnerable_packages =
2037
advisories.check_for_advisories(pkgs, !skip)
2138
|> list.map(fn(p) {
@@ -29,16 +46,15 @@ pub fn main() {
2946
_ ->
3047
pkgs
3148
|> list.map(fn(pkg) {
32-
case retired.check_retired(pkg) {
49+
case retired.check_retired(pkg, !skip) {
3350
option.Some(ret) -> option.Some(#(pkg, ret))
3451
option.None -> option.None
3552
}
3653
})
3754
|> option.values
3855
|> list.map(fn(p) {
39-
case p {
40-
#(pkg, ret) -> warning.retired_to_warning(pkg, ret)
41-
}
56+
let #(pkg, ret) = p
57+
warning.retired_to_warning(pkg, ret)
4258
})
4359
}
4460

src/go_over/retired.gleam

+11-7
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ fn pull_retired(pkg: packages.Package) {
4747
Nil
4848
}
4949

50-
pub fn check_retired(pkg: packages.Package) {
51-
pkg
52-
|> path()
53-
|> cache.pull_if_not_cached(constants.hour, fn() {
54-
let _ = simplifile.delete(path(pkg))
55-
pull_retired(pkg)
56-
})
50+
pub fn check_retired(pkg: packages.Package, pull: Bool) {
51+
case pull {
52+
True ->
53+
pkg
54+
|> path()
55+
|> cache.pull_if_not_cached(constants.hour, fn() {
56+
let _ = simplifile.delete(path(pkg))
57+
pull_retired(pkg)
58+
})
59+
False -> Nil
60+
}
5761

5862
let assert Ok(resp) =
5963
pkg

0 commit comments

Comments
 (0)