Skip to content

Commit 2e59221

Browse files
authored
Merge pull request #14 from laurentheirendt/direct-options
Implementation of automatic mode
2 parents 3d3d64a + 454b654 commit 2e59221

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

contribute.m

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function contribute(repoName, printLevel)
1+
function contribute(repoName, printLevel, autoOption)
22
% devTools
33
%
44
% PURPOSE: displays a menu and calls the respective subfunctions
@@ -7,11 +7,14 @@ function contribute(repoName, printLevel)
77
% 2. Select an existing feature (branch) to work on.
88
% 3. Publish a feature (branch).
99
% 4. Delete a feature (branch).
10+
% 5. Update the fork
1011
%
1112
% INPUT:
1213
%
14+
% repoName: Name of the repository (default: opencobra/cobratoolbox)
1315
% printLevel: 0: minimal printout (default)
1416
% 1: detailed printout (debug mode)
17+
% autoOption: menu option
1518

1619
global gitConf
1720
global gitCmd
@@ -26,14 +29,24 @@ function contribute(repoName, printLevel)
2629
% adding the src folder of the devTools
2730
addpath(genpath(fileparts(which(mfilename))));
2831

32+
% check the automatic option argument
33+
autoOptionFlag = false;
34+
if exist('autoOption', 'var')
35+
if ~isempty(autoOption) && autoOption > 0 && autoOption < 6
36+
autoOptionFlag = true;
37+
else
38+
error('Please enter an automatic menu option between 1 and 5.')
39+
end
40+
end
41+
2942
% treatment of input arguments
30-
if ~exist('repoName', 'var')
43+
if ~exist('repoName', 'var') || isempty(repoName)
3144
DEFAULTREPONAME = 'opencobra/cobratoolbox'; % set the default repository
3245
repoName = DEFAULTREPONAME;
3346
end
3447

3548
% soft reset if the repository name is different
36-
if ~isempty(gitConf)
49+
if ~isempty(gitConf) && exist('repoName', 'var') && isfield(gitConf, 'remoteUserName') && isfield(gitConf, 'remoteRepoName')
3750
if ~strcmpi(repoName, [gitConf.remoteUserName '/' gitConf.remoteRepoName])
3851
resetDevTools();
3952
end
@@ -46,8 +59,10 @@ function contribute(repoName, printLevel)
4659
checkSystem(mfilename, repoName);
4760
end
4861

62+
% perform a soft reset if interrupted
4963
finishup = onCleanup(@() resetDevTools());
5064

65+
% determine the directory of the devTools
5166
devToolsDir = fileparts(which(mfilename));
5267

5368
% change to the directory of the devTools
@@ -56,12 +71,18 @@ function contribute(repoName, printLevel)
5671
% update the devTools
5772
updateDevTools();
5873

74+
% print the launcher
5975
fprintf(gitConf.launcher);
6076

61-
choice = input('\n (You can abort any process using CTRL+C)\n\n [1] Start a new feature (branch).\n [2] Select an existing feature (branch) to work on.\n [3] Publish a feature (branch).\n [4] Delete a feature (branch).\n [5] Update the fork.\n\n -> Please select what you want to do (enter the number): ', 's');
62-
63-
choice = str2num(choice);
77+
% show the menu to select an option
78+
if autoOptionFlag
79+
choice = autoOption;
80+
else
81+
choice = input('\n (You can abort any process using CTRL+C)\n\n [1] Start a new feature (branch).\n [2] Select an existing feature (branch) to work on.\n [3] Publish a feature (branch).\n [4] Delete a feature (branch).\n [5] Update the fork.\n\n -> Please select what you want to do (enter the number): ', 's');
82+
choice = str2num(choice);
83+
end
6484

85+
% evaluate the option
6586
if length(choice) == 0 || choice > 5 || choice < 0
6687
error('Please enter a number between 1 and 5.')
6788
else

0 commit comments

Comments
 (0)