Skip to content

Commit f1b0e94

Browse files
authored
Refactoring + fmt + lint (#4)
* fmt + lint * update install script
1 parent 87e68d8 commit f1b0e94

File tree

7 files changed

+50
-36
lines changed

7 files changed

+50
-36
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
#
45
"anytree-cli",

anytree-cli/src/bin/anytree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn run() -> anyhow::Result<()> {
2222
Err(e) => {
2323
if e.to_string().starts_with("Usage") {
2424
eprintln!("{e}");
25-
return Ok(())
25+
return Ok(());
2626
}
2727
anyhow::bail!(e);
2828
}

anytree-cli/src/commands/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ pub fn build(sbom_path: impl AsRef<Path>, cache: Option<impl AsRef<str>>) -> any
88
serde_json::from_reader(File::open(sbom_path.as_ref())?)?;
99

1010
let container_name = if let Some(run_dir) = cache {
11-
// TODO: remove container with such name if it is not running otherwise throw error
12-
//docker ps -qf "name=anytree-builder-d5badd63-06bc-4db5-bfa4-165be65d4cde"
11+
// TODO: remove container with such name if it is not running otherwise
12+
// throw error docker ps -qf
13+
// "name=anytree-builder-d5badd63-06bc-4db5-bfa4-165be65d4cde"
1314
run_dir.as_ref().to_string()
1415
} else {
1516
let container_uuid = Uuid::new_v4().to_string();

anytree-plugin-cargo-dependencies/src/cargo_components/helper.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::collections::HashMap;
22
use std::fs::File;
3-
use std::hash::{Hash, Hasher, SipHasher};
3+
#[allow(deprecated)]
4+
use std::hash::SipHasher;
5+
use std::hash::{Hash, Hasher};
46
use std::io::Write;
57
use std::path::Path;
68

@@ -104,6 +106,7 @@ pub enum SourceKind {
104106
// dir suffix
105107
pub fn get_suffix_hash(url: &str, kind: Option<SourceKind>) -> String {
106108
// NOTE: SipHasher is deprecated, but cargo seems to check this hash !!!!
109+
#[allow(deprecated)]
107110
let mut hasher = SipHasher::new();
108111
if let Some(kind) = kind {
109112
kind.hash(&mut hasher);

anytree-utils/src/tracing.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::io::{BufRead, BufReader};
2+
23
use indicatif::ProgressStyle;
34
use tracing::Span;
4-
use tracing_indicatif::IndicatifLayer;
55
use tracing_indicatif::span_ext::IndicatifSpanExt;
6+
use tracing_indicatif::IndicatifLayer;
67
use tracing_subscriber::layer::SubscriberExt;
78
use tracing_subscriber::util::SubscriberInitExt;
8-
9-
use tracing_subscriber::{EnvFilter, Layer};
9+
use tracing_subscriber::EnvFilter;
1010

1111
pub fn default_init() {
1212
let indicatif_layer = IndicatifLayer::new();
@@ -21,7 +21,7 @@ pub fn default_init() {
2121
.with_ansi(true)
2222
.with_thread_ids(true)
2323
.with_source_location(false),
24-
)
24+
),
2525
)
2626
.with(EnvFilter::new(directives))
2727
.with(indicatif_layer)
@@ -36,7 +36,7 @@ pub fn default_init() {
3636
.with_ansi(true)
3737
.with_thread_ids(true)
3838
.with_source_location(false),
39-
)
39+
),
4040
)
4141
.with(EnvFilter::new("info"))
4242
.with(indicatif_layer)
@@ -72,4 +72,4 @@ pub fn start_progress(length: u64) -> Span {
7272

7373
pub fn increase_progress() {
7474
Span::current().pb_inc(1);
75-
}
75+
}

clippy.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ disallowed-methods = [
1919
# but we cannot disable them all here (because of e.g. https://github.com/rust-lang/rust-clippy/issues/10406)
2020
# so we do that in `clipppy_wasm.toml` instead.
2121
"std::thread::spawn", # Use `std::thread::Builder` and name the thread
22-
"sha1::Digest::new", # SHA1 is cryptographically broken
22+
## INFO: in anytree project we have to use this algo anyway
23+
# "sha1::Digest::new", # SHA1 is cryptographically broken
2324
"std::panic::catch_unwind", # We compile with `panic = "abort"`
2425
]
2526

install.sh

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
set -e
44

5-
REPO_OWNER=gosh-sh
6-
REPO=anytree
7-
BIN_NAME=anytree
5+
: "${REPO_OWNER:=gosh-sh}"
6+
: "${REPO:=anytree}"
7+
: "${BIN_NAME:=anytree}"
8+
89
if [[ -z "${TAG}" ]]; then
910
echo ""
1011
echo "Downloading latest release of GOSH Anytree"
@@ -18,29 +19,38 @@ else
1819
fi
1920

2021
# Check OS and architecture
21-
if [[ "$OSTYPE" == "linux-gnu" ]]; then
22-
if [[ $(uname -m) == "x86_64" ]]; then
23-
TAR="$BIN_NAME-linux-amd64.tar.gz"
24-
else
25-
TAR="$BIN_NAME-linux-arm64.tar.gz"
26-
fi
27-
else
28-
echo "Only \"Linux\" is supported - not \"$OSTYPE\""
22+
case "$OSTYPE" in
23+
"linux"*)
24+
case "$(uname -m)" in
25+
"x86_64") TAR="$BIN_NAME"-linux-amd64.tar.gz ;;
26+
*) TAR="$BIN_NAME"-linux-arm64.tar.gz ;;
27+
esac
28+
;;
29+
"darwin"*)
30+
case "$(uname -m)" in
31+
"x86_64") TAR="$BIN_NAME"-darwin-amd64.tar.gz ;;
32+
*) TAR="$BIN_NAME"-darwin-arm64.tar.gz ;;
33+
esac
34+
;;
35+
*)
36+
echo "Only \"Linux\" and \"Darwin\" are supported"
2937
exit 1
30-
fi
38+
;;
39+
esac
40+
3141

3242
OLD_TAR="${TAR%.*}"
3343
TEMP_DIR="gosh_tmp"
34-
[ -f $TAR ] && rm $TAR
35-
[ -d $OLD_TAR ] && rm -r $OLD_TAR
36-
[ -d $TEMP_DIR ] && rm -r $TEMP_DIR
44+
[[ -f $TAR ]] && rm "$TAR"
45+
[[ -d $OLD_TAR ]] && rm -r "$OLD_TAR"
46+
[[ -d $TEMP_DIR ]] && rm -r "$TEMP_DIR"
3747

3848
GH_API="https://api.github.com"
3949
GH_REPO="$GH_API/repos/${REPO_OWNER}/${REPO}"
4050
GH_TAGS="$GH_REPO/releases/$TAG"
4151

4252
# Read asset tags.
43-
response=$(curl -s "$GH_TAGS")
53+
response=$(wget -qO- "$GH_TAGS")
4454

4555
# Get ID of the asset based on the given name.
4656
eval $(echo "$response" | grep -C3 "name.:.\+$TAR" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
@@ -60,22 +70,20 @@ mkdir $TEMP_DIR
6070

6171
# Unpack the downloaded tar archive to the temporary directory
6272
if [[ -z "${OLD}" ]]; then
63-
tar -xvzf $TAR -C $TEMP_DIR
64-
rm -f $TAR
73+
tar -xvzf "$TAR" -C $TEMP_DIR
74+
rm -f "$TAR"
6575
else
66-
tar -xf $OLD_TAR -C $TEMP_DIR
67-
rm -f $OLD_TAR
76+
tar -xf "$OLD_TAR" -C $TEMP_DIR
77+
rm -f "$OLD_TAR"
6878
fi
6979

7080
DEFAULT_PATH=$HOME/.gosh/
7181
BINARY_PATH="${BINARY_PATH:-$DEFAULT_PATH}"
7282

73-
if [ ! -d $BINARY_PATH ]; then
74-
mkdir -p $BINARY_PATH
75-
fi
83+
mkdir -p "$BINARY_PATH"
7684

7785
# Move the contents from the temporary directory to the desired installation path
78-
mv $TEMP_DIR/$BIN_NAME $BINARY_PATH
86+
mv $TEMP_DIR/"$BIN_NAME" "$BINARY_PATH"
7987

8088
echo ""
8189
echo "Binary was installed to $BINARY_PATH"
@@ -89,4 +97,4 @@ if [ $ALREADY_ADDED -lt 1 ]; then
8997
fi
9098

9199
# Remove the temporary directory
92-
rm -r $TEMP_DIR
100+
rm -r $TEMP_DIR

0 commit comments

Comments
 (0)