-
Couldn't load subscription status.
- Fork 32
Add configuration file #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
19acf19
feat: ✨ Initial suppor for config file
SergioGasquez f405512
refactor: 🎨 Update config
SergioGasquez 9e39079
chore: 🎨 Code cleanup
SergioGasquez 1bfef0e
feat: ✨ Update uninstall subcommand
SergioGasquez 7a8b203
refactor: ⚡️ Improve update subcommand and add toolchain_version parser
SergioGasquez 0da0745
build: ➕ Add regex
SergioGasquez b69e7c8
docs: 📝 Add/improve fn documentation
SergioGasquez 80b5f1b
chore: ⚡️ Fix clippy warnings
SergioGasquez 329f8bd
chore: ⚡️ Fix clippy warnings
SergioGasquez 34a4b19
build: ⏪️ Revert cargo.toml
SergioGasquez da8f8b4
chore: 📌 Add MSRV
SergioGasquez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| use crate::{host_triple::HostTriple, targets::Target, toolchain::rust_toolchain::RustToolchain}; | ||
| use directories_next::ProjectDirs; | ||
| use miette::{ErrReport, IntoDiagnostic, Result, WrapErr}; | ||
| use serde::{Deserialize, Serialize}; | ||
| use std::{ | ||
| collections::HashSet, | ||
| fs::{create_dir_all, read, write}, | ||
| path::PathBuf, | ||
| }; | ||
|
|
||
| /// Deserialized contents of a configuration file | ||
| #[derive(Debug, Deserialize, Serialize, Default, Clone)] | ||
| pub struct Config { | ||
| // /// ESP-IDF version | ||
| pub espidf_version: Option<String>, | ||
| /// Destination of the generated export file. | ||
| pub export_file: PathBuf, | ||
| /// Extra crates to installed. | ||
| pub extra_crates: HashSet<String>, | ||
| /// Host triple | ||
| pub host_triple: HostTriple, | ||
| /// LLVM toolchain path. | ||
| pub llvm_path: PathBuf, | ||
| /// Nightly Rust toolchain version. | ||
| pub nightly_version: String, | ||
| /// List of targets instaled. | ||
| pub targets: HashSet<Target>, | ||
| /// Xtensa Rust toolchain. | ||
| pub xtensa_toolchain: RustToolchain, | ||
| } | ||
|
|
||
| impl Config { | ||
| /// Load the config from config file | ||
| pub fn load() -> Result<Self> { | ||
| let dirs = ProjectDirs::from("rs", "esp", "espup").unwrap(); | ||
| let file = dirs.config_dir().join("espup.toml"); | ||
|
|
||
| let config = if let Ok(data) = read(&file) { | ||
| toml::from_slice(&data).into_diagnostic()? | ||
| } else { | ||
| return Err(ErrReport::msg("No config file found")); | ||
| }; | ||
| Ok(config) | ||
| } | ||
|
|
||
| /// Save the config to file | ||
| pub fn save(&self) -> Result<()> { | ||
| let dirs = ProjectDirs::from("rs", "esp", "espup").unwrap(); | ||
| let file = dirs.config_dir().join("espup.toml"); | ||
|
|
||
| let serialized = toml::to_string(&self.clone()) | ||
| .into_diagnostic() | ||
| .wrap_err("Failed to serialize config")?; | ||
| create_dir_all(file.parent().unwrap()) | ||
| .into_diagnostic() | ||
| .wrap_err("Failed to create config directory")?; | ||
| write(&file, serialized) | ||
| .into_diagnostic() | ||
| .wrap_err_with(|| format!("Failed to write config to {}", file.display())) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub mod config; | ||
| pub mod emoji; | ||
| pub mod host_triple; | ||
| pub mod targets; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.