mirror of
				https://github.com/davidgiven/fluxengine.git
				synced 2025-10-24 11:11:02 -07:00 
			
		
		
		
	Config files are now specified with -c, rather than via filename
arguments, because otherwise you get really unhelpful error messages when you get things wrong.
This commit is contained in:
		
							
								
								
									
										18
									
								
								build.py
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								build.py
									
									
									
									
									
								
							| @@ -28,7 +28,7 @@ else: | ||||
|         ("acorndfs", "", "--200"), | ||||
|         ("agat", "", ""), | ||||
|         ("amiga", "", ""), | ||||
|         ("apple2", "", "--140 40track_drive"), | ||||
|         ("apple2", "", "--140 -c 40track_drive"), | ||||
|         ("atarist", "", "--360"), | ||||
|         ("atarist", "", "--370"), | ||||
|         ("atarist", "", "--400"), | ||||
| @@ -38,17 +38,17 @@ else: | ||||
|         ("atarist", "", "--800"), | ||||
|         ("atarist", "", "--820"), | ||||
|         ("bk", "", ""), | ||||
|         ("brother", "", "--120 40track_drive"), | ||||
|         ("brother", "", "--120 -c 40track_drive"), | ||||
|         ("brother", "", "--240"), | ||||
|         ( | ||||
|             "commodore", | ||||
|             "scripts/commodore1541_test.textpb", | ||||
|             "--171 40track_drive", | ||||
|             "--171 -c 40track_drive", | ||||
|         ), | ||||
|         ( | ||||
|             "commodore", | ||||
|             "scripts/commodore1541_test.textpb", | ||||
|             "--192 40track_drive", | ||||
|             "--192 -c 40track_drive", | ||||
|         ), | ||||
|         ("commodore", "", "--800"), | ||||
|         ("commodore", "", "--1620"), | ||||
| @@ -60,17 +60,17 @@ else: | ||||
|         ("ibm", "", "--1232"), | ||||
|         ("ibm", "", "--1440"), | ||||
|         ("ibm", "", "--1680"), | ||||
|         ("ibm", "", "--180 40track_drive"), | ||||
|         ("ibm", "", "--160 40track_drive"), | ||||
|         ("ibm", "", "--320 40track_drive"), | ||||
|         ("ibm", "", "--360 40track_drive"), | ||||
|         ("ibm", "", "--180 -c 40track_drive"), | ||||
|         ("ibm", "", "--160 -c 40track_drive"), | ||||
|         ("ibm", "", "--320 -c 40track_drive"), | ||||
|         ("ibm", "", "--360 -c 40track_drive"), | ||||
|         ("ibm", "", "--720_96"), | ||||
|         ("ibm", "", "--720_135"), | ||||
|         ("mac", "scripts/mac400_test.textpb", "--400"), | ||||
|         ("mac", "scripts/mac800_test.textpb", "--800"), | ||||
|         ("n88basic", "", ""), | ||||
|         ("rx50", "", ""), | ||||
|         ("tartu", "", "--390 40track_drive"), | ||||
|         ("tartu", "", "--390 -c 40track_drive"), | ||||
|         ("tartu", "", "--780"), | ||||
|         ("tids990", "", ""), | ||||
|         ("victor9k", "", "--612"), | ||||
|   | ||||
| @@ -13,17 +13,23 @@ static std::vector<Flag*> all_flags; | ||||
| static std::map<const std::string, Flag*> flags_by_name; | ||||
|  | ||||
| static void doHelp(); | ||||
| static void doLoadConfig(const std::string& filename); | ||||
| static void doShowConfig(); | ||||
| static void doDoc(); | ||||
|  | ||||
| static FlagGroup helpGroup; | ||||
| static ActionFlag helpFlag = ActionFlag({"--help"}, "Shows the help.", doHelp); | ||||
|  | ||||
| static ActionFlag showConfigFlag = ActionFlag({"--config", "-C"}, | ||||
| static FlagGroup configGroup; | ||||
| static ActionFlag loadConfigFlag({"--config", "-c"}, | ||||
|     "Reads an internal or external configuration file.", | ||||
|     doLoadConfig); | ||||
|  | ||||
| static ActionFlag showConfigFlag({"--show-config", "-C"}, | ||||
|     "Shows the currently set configuration and halts.", | ||||
|     doShowConfig); | ||||
|  | ||||
| static ActionFlag docFlag = ActionFlag( | ||||
| static ActionFlag docFlag( | ||||
|     {"--doc"}, "Shows the available configuration options and halts.", doDoc); | ||||
|  | ||||
| FlagGroup::FlagGroup() | ||||
| @@ -182,17 +188,16 @@ void FlagGroup::parseFlags(int argc, | ||||
|             "non-option parameter '{}' seen (try --help)", *filenames.begin()); | ||||
| } | ||||
|  | ||||
| static void doLoadConfig(const std::string& filename) | ||||
| { | ||||
|     globalConfig().readBaseConfigFile(filename); | ||||
| } | ||||
|  | ||||
| void FlagGroup::parseFlagsWithConfigFiles(int argc, | ||||
|     const char* argv[], | ||||
|     const std::map<std::string, const ConfigProto*>& configFiles) | ||||
| { | ||||
|     parseFlags(argc, | ||||
|         argv, | ||||
|         [&](const auto& filename) | ||||
|         { | ||||
|             globalConfig().readBaseConfigFile(filename); | ||||
|             return true; | ||||
|         }); | ||||
|     FlagGroup({this, &configGroup}).parseFlags(argc, argv); | ||||
| } | ||||
|  | ||||
| void FlagGroup::checkInitialised() const | ||||
|   | ||||
| @@ -83,13 +83,23 @@ public: | ||||
|         const std::string helptext, | ||||
|         std::function<void(void)> callback): | ||||
|         Flag(names, helptext), | ||||
|         _callback(callback) | ||||
|         _voidCallback(callback), | ||||
|         _hasArgument(false) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     ActionFlag(const std::vector<std::string>& names, | ||||
|         const std::string helptext, | ||||
|         std::function<void(const std::string&)> callback): | ||||
|         Flag(names, helptext), | ||||
|         _callback(callback), | ||||
|         _hasArgument(true) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     bool hasArgument() const override | ||||
|     { | ||||
|         return false; | ||||
|         return _hasArgument; | ||||
|     } | ||||
|  | ||||
|     const std::string defaultValueAsString() const override | ||||
| @@ -99,11 +109,16 @@ public: | ||||
|  | ||||
|     void set(const std::string& value) override | ||||
|     { | ||||
|         _callback(); | ||||
|         if (_hasArgument) | ||||
|             _callback(value); | ||||
|         else | ||||
|             _voidCallback(); | ||||
|     } | ||||
|  | ||||
| private: | ||||
|     const std::function<void(void)> _callback; | ||||
|     const std::function<void(const std::string&)> _callback; | ||||
|     const std::function<void(void)> _voidCallback; | ||||
|     bool _hasArgument; | ||||
| }; | ||||
|  | ||||
| class SettableFlag : public Flag | ||||
|   | ||||
| @@ -14,10 +14,10 @@ destfile=$dir/dest.img | ||||
|  | ||||
| dd if=/dev/urandom of=$srcfile bs=1048576 count=2 2>&1 | ||||
|  | ||||
| echo $fluxengine write $format -i $srcfile -d $fluxfile --drive.rotational_period_ms=200 $flags | ||||
| $fluxengine write $format -i $srcfile -d $fluxfile --drive.rotational_period_ms=200 $flags | ||||
| echo $fluxengine read $format -s $fluxfile -o $destfile --drive.rotational_period_ms=200 $flags | ||||
| $fluxengine read $format -s $fluxfile -o $destfile --drive.rotational_period_ms=200 $flags | ||||
| echo $fluxengine write -c $format -i $srcfile -d $fluxfile --drive.rotational_period_ms=200 $flags | ||||
| $fluxengine write -c $format -i $srcfile -d $fluxfile --drive.rotational_period_ms=200 $flags | ||||
| echo $fluxengine read -c $format -s $fluxfile -o $destfile --drive.rotational_period_ms=200 $flags | ||||
| $fluxengine read -c $format -s $fluxfile -o $destfile --drive.rotational_period_ms=200 $flags | ||||
| if [ ! -s $destfile ]; then | ||||
| 	echo "Zero length output file!" >&2 | ||||
| 	exit 1 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user