@@ -105,10 +105,20 @@ public Docker visitStage(Docker.Stage stage, PrintOutputCapture<P> p) {
105105 return stage ;
106106 }
107107
108+ private void instructionName (Docker .Instruction instruction , PrintOutputCapture <P > p ) {
109+ String defaultName = instruction .getClass ().getSimpleName ();
110+ p .append (
111+ instruction .getMarkers ().findFirst (InstructionName .class )
112+ .filter (f -> f .getName ().equalsIgnoreCase (defaultName ))
113+ .map (InstructionName ::getName )
114+ .orElseGet (defaultName ::toUpperCase )
115+ );
116+ }
117+
108118 @ Override
109119 public Docker visitFrom (Docker .From from , PrintOutputCapture <P > p ) {
110120 beforeSyntax (from , p );
111- p . append ( "FROM" );
121+ instructionName ( from , p );
112122 if (from .getPlatform () != null && !StringUtils .isBlank (from .getPlatform ().getText ())) {
113123 visitSpace (from .getPlatform ().getPrefix (), p );
114124 if (!from .getPlatform ().getText ().startsWith ("--" )) {
@@ -173,7 +183,7 @@ public Docker visitDirective(Docker.Directive directive, PrintOutputCapture<P> p
173183 @ Override
174184 public Docker visitRun (Docker .Run run , PrintOutputCapture <P > p ) {
175185 beforeSyntax (run , p );
176- p . append ( "RUN" );
186+ instructionName ( run , p );
177187 if (run .getOptions () != null ) {
178188 run .getOptions ().forEach (o -> {
179189 visitOption (o , p );
@@ -193,7 +203,7 @@ public Docker visitRun(Docker.Run run, PrintOutputCapture<P> p) {
193203 @ Override
194204 public Docker visitCmd (Docker .Cmd cmd , PrintOutputCapture <P > p ) {
195205 beforeSyntax (cmd , p );
196- p . append ( "CMD" );
206+ instructionName ( cmd , p );
197207 Form form = cmd .getForm ();
198208 if (form == null ) {
199209 form = Form .EXEC ;
@@ -299,7 +309,7 @@ private Docker.KeyArgs visitKeyArgs(Docker.KeyArgs keyArgs, PrintOutputCapture<P
299309 @ Override
300310 public Docker visitLabel (Docker .Label label , PrintOutputCapture <P > p ) {
301311 beforeSyntax (label , p );
302- p . append ( "LABEL" );
312+ instructionName ( label , p );
303313 for (DockerRightPadded <Docker .KeyArgs > padded : label .getArgs ()) {
304314 visitKeyArgs (padded .getElement (), p );
305315 visitSpace (padded .getAfter (), p );
@@ -311,7 +321,7 @@ public Docker visitLabel(Docker.Label label, PrintOutputCapture<P> p) {
311321 @ Override
312322 public Docker visitMaintainer (Docker .Maintainer maintainer , PrintOutputCapture <P > p ) {
313323 beforeSyntax (maintainer , p );
314- p . append ( "MAINTAINER" );
324+ instructionName ( maintainer , p );
315325 visitLiteral (maintainer .getName (), p );
316326 afterSyntax (maintainer , p );
317327 return maintainer ;
@@ -320,7 +330,7 @@ public Docker visitMaintainer(Docker.Maintainer maintainer, PrintOutputCapture<P
320330 @ Override
321331 public Docker visitExpose (Docker .Expose expose , PrintOutputCapture <P > p ) {
322332 beforeSyntax (expose , p );
323- p . append ( "EXPOSE" );
333+ instructionName ( expose , p );
324334 for (int i = 0 ; i < expose .getPorts ().size (); i ++) {
325335 DockerRightPadded <Docker .Port > padded = expose .getPorts ().get (i );
326336 Docker .Port port = padded .getElement ();
@@ -347,7 +357,7 @@ private void visitQuoting(Quoting quoting, PrintOutputCapture<P> p) {
347357 @ Override
348358 public Docker visitEnv (Docker .Env env , PrintOutputCapture <P > p ) {
349359 beforeSyntax (env , p );
350- p . append ( "ENV" );
360+ instructionName ( env , p );
351361
352362 for (DockerRightPadded <Docker .KeyArgs > padded : env .getArgs ()) {
353363 Docker .KeyArgs kvp = padded .getElement ();
@@ -374,7 +384,7 @@ public Docker visitEnv(Docker.Env env, PrintOutputCapture<P> p) {
374384 @ Override
375385 public Docker visitAdd (Docker .Add add , PrintOutputCapture <P > p ) {
376386 beforeSyntax (add , p );
377- p . append ( "ADD" );
387+ instructionName ( add , p );
378388
379389 if (add .getOptions () != null ) {
380390 add .getOptions ().forEach (o -> {
@@ -397,7 +407,7 @@ public Docker visitAdd(Docker.Add add, PrintOutputCapture<P> p) {
397407 @ Override
398408 public Docker visitCopy (Docker .Copy copy , PrintOutputCapture <P > p ) {
399409 beforeSyntax (copy , p );
400- p . append ( "COPY" );
410+ instructionName ( copy , p );
401411
402412 if (copy .getOptions () != null ) {
403413 copy .getOptions ().forEach (o -> {
@@ -420,7 +430,7 @@ public Docker visitCopy(Docker.Copy copy, PrintOutputCapture<P> p) {
420430 @ Override
421431 public Docker visitEntrypoint (Docker .Entrypoint entrypoint , PrintOutputCapture <P > p ) {
422432 beforeSyntax (entrypoint , p );
423- p . append ( "ENTRYPOINT" );
433+ instructionName ( entrypoint , p );
424434
425435 if (entrypoint .getForm () == Form .EXEC ) {
426436 Space before = entrypoint .getExecFormPrefix ();
@@ -460,7 +470,7 @@ public Docker visitEntrypoint(Docker.Entrypoint entrypoint, PrintOutputCapture<P
460470 @ Override
461471 public Docker visitVolume (Docker .Volume volume , PrintOutputCapture <P > p ) {
462472 beforeSyntax (volume , p );
463- p . append ( "VOLUME" );
473+ instructionName ( volume , p );
464474
465475 if (volume .getForm () == Form .EXEC ) {
466476 Space before = volume .getExecFormPrefix ();
@@ -499,7 +509,7 @@ public Docker visitVolume(Docker.Volume volume, PrintOutputCapture<P> p) {
499509 @ Override
500510 public Docker visitUser (Docker .User user , PrintOutputCapture <P > p ) {
501511 beforeSyntax (user , p );
502- p . append ( "USER" );
512+ instructionName ( user , p );
503513 visitSpace (user .getUsername ().getPrefix (), p );
504514 p .append (user .getUsername ().getText ());
505515 visitSpace (user .getUsername ().getTrailing (), p );
@@ -516,7 +526,7 @@ public Docker visitUser(Docker.User user, PrintOutputCapture<P> p) {
516526 @ Override
517527 public Docker visitWorkdir (Docker .Workdir workdir , PrintOutputCapture <P > p ) {
518528 beforeSyntax (workdir , p );
519- p . append ( "WORKDIR" );
529+ instructionName ( workdir , p );
520530 visitLiteral (workdir .getPath (), p );
521531 afterSyntax (workdir , p );
522532 return workdir ;
@@ -525,7 +535,7 @@ public Docker visitWorkdir(Docker.Workdir workdir, PrintOutputCapture<P> p) {
525535 @ Override
526536 public Docker visitArg (Docker .Arg arg , PrintOutputCapture <P > p ) {
527537 beforeSyntax (arg , p );
528- p . append ( "ARG" );
538+ instructionName ( arg , p );
529539 arg .getArgs ().forEach (padded -> {
530540 Docker .KeyArgs args = padded .getElement ();
531541 if (args .getValue ().getText () != null ) {
@@ -544,7 +554,8 @@ public Docker visitArg(Docker.Arg arg, PrintOutputCapture<P> p) {
544554 @ Override
545555 public Docker visitOnBuild (Docker .OnBuild onBuild , PrintOutputCapture <P > p ) {
546556 beforeSyntax (onBuild , p );
547- p .append ("ONBUILD " );
557+ instructionName (onBuild , p );
558+ p .append (" " );
548559 visit (onBuild .getInstruction (), p );
549560 afterSyntax (onBuild , p );
550561 return onBuild ;
@@ -553,7 +564,7 @@ public Docker visitOnBuild(Docker.OnBuild onBuild, PrintOutputCapture<P> p) {
553564 @ Override
554565 public Docker visitStopSignal (Docker .StopSignal stopSignal , PrintOutputCapture <P > p ) {
555566 beforeSyntax (stopSignal , p );
556- p . append ( "STOPSIGNAL" );
567+ instructionName ( stopSignal , p );
557568 visitSpace (stopSignal .getPrefix (), p );
558569 visitLiteral (stopSignal .getSignal (), p );
559570 afterSyntax (stopSignal , p );
@@ -563,7 +574,7 @@ public Docker visitStopSignal(Docker.StopSignal stopSignal, PrintOutputCapture<P
563574 @ Override
564575 public Docker visitHealthcheck (Docker .Healthcheck healthcheck , PrintOutputCapture <P > p ) {
565576 beforeSyntax (healthcheck , p );
566- p . append ( "HEALTHCHECK" );
577+ instructionName ( healthcheck , p );
567578
568579 if (healthcheck .getType () == Docker .Healthcheck .Type .NONE ) {
569580 p .append (" NONE" );
@@ -612,7 +623,7 @@ public Docker visitHealthcheck(Docker.Healthcheck healthcheck, PrintOutputCaptur
612623 @ Override
613624 public Docker visitShell (Docker .Shell shell , PrintOutputCapture <P > p ) {
614625 beforeSyntax (shell , p );
615- p . append ( "SHELL" );
626+ instructionName ( shell , p );
616627 if ("" .equals (shell .getExecFormPrefix ().getWhitespace ())) {
617628 p .append (" " );
618629 } else {
0 commit comments