Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Devtools\Bin\Requiresnapshot Class Reference
Inheritance diagram for Hoa\Devtools\Bin\Requiresnapshot:

Public Member Functions

 main ()
 
 usage ()
 
- Public Member Functions inherited from Hoa\Console\Dispatcher\Kit
 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 getOption (&$optionValue, $short=null)
 
 setOptions (Array $options)
 
 makeUsageOptionsList (Array $definitions=[])
 
 resolveOptionAmbiguity (Array $solutions)
 
 status ($text, $status)
 
 readLine ($prefix=null)
 
 readPassword ($prefix=null)
 
- Public Member Functions inherited from Hoa\Dispatcher\Kit
 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 construct ()
 

Protected Attributes

 $options
 
- Protected Attributes inherited from Hoa\Console\Dispatcher\Kit
 $options = null
 
 $_options = null
 

Additional Inherited Members

- Public Attributes inherited from Hoa\Console\Dispatcher\Kit
 $parser = null
 
- Public Attributes inherited from Hoa\Dispatcher\Kit
 $router = null
 
 $dispatcher = null
 
 $view = null
 
 $data = null
 

Detailed Description

Class .

Check if a library requires a new snapshot or not.

Definition at line 49 of file Requiresnapshot.php.

Member Function Documentation

Hoa\Devtools\Bin\Requiresnapshot::main ( )

The entry method.

Returns
int

Definition at line 72 of file Requiresnapshot.php.

73  {
74  $verbose = Console::isDirect(STDOUT);
75  $printSnapshot = false;
76  $printDays = false;
77  $printCommits = false;
78 
79  while (false !== $c = $this->getOption($v)) {
80  switch ($c) {
81  case '__ambiguous':
82  $this->resolveOptionAmbiguity($v);
83 
84  break;
85 
86  case 'V':
87  $verbose = false;
88 
89  break;
90 
91  case 's':
92  $printSnapshot = true;
93 
94  break;
95 
96  case 'd':
97  $printDays = true;
98 
99  break;
100 
101  case 'c':
102  $printCommits = true;
103 
104  break;
105 
106  case 'h':
107  case '?':
108  default:
109  return $this->usage();
110  }
111  }
112 
113  $this->parser->listInputs($repositoryRoot);
114 
115  if (empty($repositoryRoot)) {
116  return $this->usage();
117  }
118 
119  if (false === file_exists($repositoryRoot . DS . '.git')) {
120  throw new Console\Exception(
121  '%s is not a valid Git repository.',
122  0,
123  $repositoryRoot
124  );
125  }
126 
128  'git --git-dir=' . $repositoryRoot . '/.git ' .
129  'describe --abbrev=0 --tags origin/master'
130  );
131 
132  if (empty($tag)) {
133  throw new Console\Exception('No tag.', 1);
134  }
135 
136  $timeZone = new \DateTimeZone('UTC');
137  $snapshotDT = \DateTime::createFromFormat(
138  '*.y.m.d',
139  $tag,
140  $timeZone
141  );
142  $sixWeeks = new \DateInterval('P6W');
143  $nextSnapshotDT = clone $snapshotDT;
144  $nextSnapshotDT->add($sixWeeks);
145  $today = new \DateTime('now', $timeZone);
146 
147  $needNewSnapshot = '+' === $nextSnapshotDT->diff($today)->format('%R');
148  $numberOfDays = 0;
149  $numberOfCommits = 0;
150  $output = 'No snapshot is required.';
151 
152  if (true === $needNewSnapshot) {
153  $numberOfDays = (int) $nextSnapshotDT->diff($today)->format('%a');
154  $numberOfCommits = (int) Console\Processus::execute(
155  'git --git-dir=' . $repositoryRoot . '/.git ' .
156  'rev-list ' . $tag . '..origin/master --count'
157  );
158  $needNewSnapshot = 0 < $numberOfCommits;
159 
160  if (true === $needNewSnapshot) {
161  $output =
162  'A snapshot is required, since ' . $numberOfDays .
163  ' day' . (1 < $numberOfDays ? 's' : '') .
164  ' (tag ' . $tag . ', ' . $numberOfCommits .
165  ' commit' . (1 < $numberOfCommits ? 's' : '') .
166  ' to publish)!';
167  }
168  }
169 
170  if (true === $printSnapshot ||
171  true === $printDays ||
172  true === $printCommits) {
173  $columns = [];
174 
175  if (true === $printSnapshot) {
176  $columns[] = $tag;
177  }
178 
179  if (true === $printDays) {
180  $columns[] =
181  $numberOfDays . ' day' .
182  (1 < $numberOfDays ? 's' : '');
183  }
184 
185  if (true === $printCommits) {
186  $columns[] =
187  $numberOfCommits . ' commit' .
188  (1 < $numberOfCommits ? 's' : '');
189  }
190 
191  echo implode("\t", $columns), "\n";
192  } elseif (true === $verbose) {
193  echo $output, "\n";
194  }
195 
196  return !$needNewSnapshot;
197  }
static execute($commandLine, $escape=true)
Definition: Processus.php:1165
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190
static isDirect($pipe)
Definition: Console.php:261

Here is the call graph for this function:

Hoa\Devtools\Bin\Requiresnapshot::usage ( )

The command usage.

Returns
int

Definition at line 204 of file Requiresnapshot.php.

205  {
206  echo
207  'Usage : devtools:requiresnapshot <options> repository-root', "\n",
208  'Options :', "\n",
209  $this->makeUsageOptionsList([
210  'V' => 'No-verbose, i.e. be as quiet as possible, just ' .
211  'print essential informations.',
212  's' => 'Print the latest snapshot name in a column.',
213  'd' => 'Print the number of days since the latest ' .
214  'snapshot in a column.',
215  'c' => 'Print the number of commits since the latest ' .
216  'snapshot in a column.',
217  'help' => 'This help.'
218  ]), "\n";
219 
220  return;
221  }
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Hoa\Devtools\Bin\Requiresnapshot::$options
protected
Initial value:
= [
['no-verbose', Console\GetOption::NO_ARGUMENT, 'V'],
['snapshot', Console\GetOption::NO_ARGUMENT, 's'],
['commits', Console\GetOption::NO_ARGUMENT, 'c'],
]

Definition at line 56 of file Requiresnapshot.php.


The documentation for this class was generated from the following file: