Skip to content

Commit

Permalink
fix: replace new constructor with try_from for struct Config
Browse files Browse the repository at this point in the history
  • Loading branch information
Mcdostone committed Jan 18, 2025
1 parent f2f7a9b commit 655754c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/semver-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:

on:
pull_request:
types: [review_requested, ready_for_review]
types: [opened, reopened, synchronize, ready_for_review]
branches:
- main
paths-ignore:
Expand All @@ -39,6 +39,9 @@ jobs:
exit 1
fi
cargo-semver-checks:



needs: check-branches
permissions:
pull-requests: write
Expand All @@ -48,6 +51,13 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Delete old cargo-semver-checks comments
continue-on-error: true
run: |

Check failure on line 56 in .github/workflows/semver-checks.yml

View workflow job for this annotation

GitHub Actions / actionlint

"github.head_ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions for more details
gh pr view "${{ github.head_ref }}" --json comments --jq '.comments[] | select(.author.login == "github-actions") | .url' | grep -E 'issuecomment-(.+)' | cut -d '-' -f2 > comments.txt
xargs -I {} gh api -X DELETE "/repos/MAIF/yozefu/issues/comments/{}" < comments.txt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
target
.vscode
**/*DS_Store
akhq
Expand All @@ -8,6 +8,7 @@ lol/rust/Cargo.lock
semver-checks/
demo.sh
ee.json
.github/

crates/**/*.cdx.xml
crates/**/*.cdx.json
Expand Down
7 changes: 7 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ services:
timeout: 1s
retries: 10

yozefu:
container_name: yozefu
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped

akhq:
container_name: yozefu-akhq
image: tchiotludo/akhq
Expand Down
14 changes: 9 additions & 5 deletions crates/app/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ fn default_show_shortcuts() -> bool {
true
}

impl Config {
pub fn new(path: &Path) -> Self {
Self {
impl TryFrom<&PathBuf> for Config {
type Error = Error;

fn try_from(path: &PathBuf) -> Result<Self, Self::Error> {
Ok(Self {
path: path.to_path_buf(),
yozefu_directory: PathBuf::default(),
yozefu_directory: Self::yozefu_directory()?,
logs: None,
default_url_template: default_url_template(),
history: EXAMPLE_PROMPTS.iter().map(|e| e.to_string()).collect_vec(),
Expand All @@ -126,9 +128,11 @@ impl Config {
theme: default_theme(),
show_shortcuts: true,
export_directory: default_export_directory(),
}
})
}
}

impl Config {
/// The default config file path
pub fn path() -> Result<PathBuf, Error> {
Self::yozefu_directory().map(|d| d.join("config.json"))
Expand Down
2 changes: 1 addition & 1 deletion crates/command/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn init_config_file() -> Result<PathBuf, Error> {
if fs::metadata(&path).is_ok() {
return Ok(path);
}
let mut config = Config::new(&path);
let mut config = Config::try_from(&path)?;
let mut localhost_config = IndexMap::new();
localhost_config.insert(
"bootstrap.servers".to_string(),
Expand Down

0 comments on commit 655754c

Please sign in to comment.