Browse Source

Allow running jobsets in cli by description (and uuid)

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20033
pull/18/head
Marek Roszko 6 months ago
parent
commit
2d327d9d73
  1. 28
      common/jobs/jobset.cpp
  2. 6
      common/jobs/jobset.h
  3. 2
      kicad/cli/command_jobset_run.cpp

28
common/jobs/jobset.cpp

@ -36,7 +36,7 @@
const int jobsFileSchemaVersion = 1;
KICOMMON_API std::map<JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO> JobsetDestinationTypeInfos =
KICOMMON_API std::map<JOBSET_DESTINATION_T, JOBSET_DESTINATION_T_INFO> JobsetDestinationTypeInfos =
{
{ JOBSET_DESTINATION_T::FOLDER,
{ _HKI( "Folder" ), BITMAPS::small_folder, true, "" } },
@ -286,16 +286,24 @@ bool JOBSET::SaveToFile( const wxString& aDirectory, bool aForce )
}
JOBSET_DESTINATION* JOBSET::GetDestination( wxString& aDestination )
JOBSET_DESTINATION* JOBSET::FindDestination( wxString& aDestinationStr )
{
auto it = std::find_if( m_destinations.begin(), m_destinations.end(),
[&]( const JOBSET_DESTINATION& destination )
{
if( destination.m_id == aDestination )
return true;
return false;
} );
auto is_matching_dest = [&]( const JOBSET_DESTINATION& destination )
{
if( destination.m_id == aDestinationStr || destination.m_description == aDestinationStr )
return true;
return false;
};
auto count = std::count_if( m_destinations.begin(), m_destinations.end(), is_matching_dest );
// we want to intentionally fail if more than one matching dest exists
// as theres no good way to handle it
if( count != 1 )
return nullptr;
auto it = std::find_if( m_destinations.begin(), m_destinations.end(), is_matching_dest );
if( it != m_destinations.end() )
return &(*it);

6
common/jobs/jobset.h

@ -120,7 +120,11 @@ public:
std::vector<JOBSET_DESTINATION>& GetDestinations() { return m_destinations; }
JOBSET_DESTINATION* GetDestination( wxString& aDestination );
/**
* Attempts to find a destination based on the given string
* Both the uuid of the destination and description name are used
*/
JOBSET_DESTINATION* FindDestination( wxString& aDestinationStr );
bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override;

2
kicad/cli/command_jobset_run.cpp

@ -87,7 +87,7 @@ int CLI::JOBSET_RUN_COMMAND::doPerform( KIWAY& aKiway )
if( !outputKey.IsEmpty() )
{
JOBSET_DESTINATION* destination = jobFile.GetDestination( outputKey );
JOBSET_DESTINATION* destination = jobFile.FindDestination( outputKey );
if( destination == nullptr || !jobsRunner.RunJobsForDestination( destination, bail ) )
return_code = CLI::EXIT_CODES::ERR_JOBS_RUN_FAILED;

Loading…
Cancel
Save