forked from gamer-project/gamer
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a feature that read and write `.local_settings` (repository level) and `global_settings` (user level) files to save the default machine. Add tool/set_settings.sh script to setup the default machine. In src/configure.py: - Change the default of `--machine` to None. - Add function `get_machine()` to read the default machine setting. - Raise FileNotFoundError if the .config file is not found. Add `src/.local_settings` to .gitignore.
- Loading branch information
1 parent
430fe01
commit 1f66a18
Showing
3 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -14,3 +14,4 @@ GAMER_ExtractProfile | |
.vscode | ||
src/Makefile | ||
src/Makefile.log | ||
src/.local_settings |
This file contains 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 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,63 @@ | ||
#!/bin/bash | ||
|
||
cd "$(dirname "$0")" | ||
|
||
show_help() { | ||
echo "Usage: $0 [--local | --global] --machine=<name>" | ||
echo "" | ||
echo "Options:" | ||
echo " --local Use local settings" | ||
echo " --global Use global settings" | ||
echo " --machine=<name> Specify the machine name" | ||
echo " -h, --help Show this help message" | ||
} | ||
|
||
# Parse arguments | ||
LOCAL=false | ||
GLOBAL=false | ||
MACHINE="" | ||
|
||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
--local) LOCAL=true ;; | ||
--global) GLOBAL=true ;; | ||
--machine=*) MACHINE="${1#*=}" ;; | ||
-h|--help) show_help; exit 0 ;; | ||
--machine) echo "Error: Use --machine=<name> to specify the machine."; exit 1 ;; | ||
*) echo "Unknown parameter passed: $1"; echo "Use -h or --help for usage information."; exit 1 ;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ -z "$MACHINE" ]; then | ||
echo "Error: --machine option is required." | ||
exit 1 | ||
fi | ||
|
||
if [ "$LOCAL" = true ] && [ "$GLOBAL" = true ]; then | ||
echo "Error: Cannot specify both --local and --global." | ||
exit 1 | ||
elif [ "$LOCAL" = true ]; then | ||
SETTING_FILE="../src/.local_settings" | ||
SETTING_TYPE="local" | ||
elif [ "$GLOBAL" = true ]; then | ||
SETTING_FILE="$HOME/.config/gamer/global_settings" | ||
SETTING_TYPE="global" | ||
else | ||
echo "Error: Specify either --local or --global." | ||
exit 1 | ||
fi | ||
|
||
mkdir -p "$(dirname "$SETTING_FILE")" | ||
|
||
# Write the machine name to the setting file | ||
echo "# GAMER setting file" > "$SETTING_FILE" | ||
echo "machine_name $MACHINE" >> "$SETTING_FILE" | ||
|
||
# Check if the write was successful | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to write to $SETTING_FILE." | ||
exit 1 | ||
fi | ||
|
||
echo "Successfully wrote $SETTING_TYPE settings to $SETTING_FILE for machine='$MACHINE'." |