docker wrapper

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
export TTY

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

stdin_exists() {
    ! [ -t 0 ] && ! test "$(readlink /proc/$$/fd/0)" = /dev/null
}

if ! stdin_exists; then
    echo stdin required 1>&2
    exit 1
fi

otype=txt

while [ $# -gt 0 ]; do opt="$1"; case "$opt" in
    "") { shift; }; ;;
    -svg) {
        otype=svg
        shift
    }
    ;;

    *) break;
esac; done

{
    case "$otype" in
        txt) {
            sed 's/ =[^ ]*= / -> /' |
            sed 's/ ~[^ ]*~ / -> /' |
            sed 's/ \.[^ ]*\. / -> /' |
            sed 's/ -[^ ]*- / -> /'
        }
        ;;

        *) {
            cat
        }
        ;;
    esac
} | /usr/bin/docker run -i --entrypoint= think/plantuml:8059 java "-Djava.awt.headless=true" -jar plantuml.jar -p "-t$otype" "$@"

ascii

Sadly, with ascii there is a limited set of arrows. I make all linkages into the basic -> using sed.

Examples

deployment diagram components

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@startuml
actor actor
agent agent
artifact artifact
boundary boundary
card card
cloud cloud
component component
control control
database database
entity entity
file file
folder folder
frame frame
interface  interface
node node
package package
queue queue
stack stack
rectangle rectangle
storage storage
usecase usecase
@enduml
 ,-----.  ,-----.   ,--------.   ,--------.   ,----.
 |actor|  |agent|   |artifact|   |boundary|   |card|
 |-----|  |-----|   |--------|   |--------|   |----|
 |-----|--|-----|---|--------|---|--------|---|----|
 `-----'  `-----'   `--------'   `--------'   `----'
    |
    |
 ,-----.  ,---------.   ,-------.   ,--------.   ,------.
 |cloud|  |component|   |control|   |database|   |entity|
 |-----|--|---------|---|-------|---|--------|---|------|
 |-----|  |---------|   |-------|   |--------|   |------|
 `-----'  `---------'   `-------'   `--------'   `------'
    |
 ,----.   ,------.   ,-----.   ,---------.  ,----.
 |file|   |folder|   |frame|   |interface|  |node|
 |----|   |------|   |-----|   |---------|  |----|
 |----|---|------|---|-----|-- |---------|--|----|
 `----'   `------'   `-----'   `---------'  `----'
    |

,-------.  ,-----.   ,-----.   ,---------.   ,-------.
|package|  |queue|   |stack|   |rectangle|   |storage|
|-------|--|-----|---|-----|---|---------|---|-------|
|-------|  |-----|   |-----|   |---------|   |-------|
`-------'  `-----'   `-----'   `---------'   `-------'
    |
,-------.
|usecase|
|-------|
|-------|
`-------'

grouping components

Groups don’t show up in ascii.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@startuml

package "Some Group" {
  HTTP - [First Component]
  [Another Component]
}

node "Other Groups" {
  FTP - [Second Component]
  [First Component] --> FTP
}

cloud {
  [Example 1]
}


database "MySql" {
  folder "This is my folder" {
    [Folder 3]
  }
  frame "Foo" {
    [Frame 4]
  }
}


[Another Component] --> [Example 1]
[Example 1] --> [Folder 3]
[Folder 3] --> [Frame 4]

@enduml

arrow direction

Arrow direction doesn’t show in ASCII.

1
2
3
4
@startuml
Interface1 <-- [Component]
Interface2 <- [Component]
@enduml
1
2
3
4
5
6
@startuml
[Component] -left-> left
[Component] -right-> right
[Component] -up-> up
[Component] -down-> down
@enduml

cloud

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@startuml

cloud cloud1
cloud cloud2
cloud cloud3
cloud cloud4
cloud cloud5
cloud1 -0- cloud2
cloud1 -0)- cloud3
cloud1 -(0- cloud4
cloud1 -(0)- cloud5

@enduml

linking

ASCII doesn’t show the different types of links.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@startuml

node node1
node node2
node node3
node node4
node node5
node1 -- node2 : label1
node1 .. node3 : label2
node1 ~~ node4 : label3
node1 == node5

@enduml

class diagram

1
2
3
4
5
6
7
8
@startuml
class User {
  -String id
  -String name
  +String name()
}
User <|-- SpecificUser
@enduml
,--------------.
|User          |
|--------------|
|-String id    |
|-String name  |
|--------------|
|+String name()|
`--------------'
        |
        |
 ,------------.
 |SpecificUser|
 |------------|
 |------------|
 `------------'

sequence diagram

This sequence diagram is rendered nicely in ASCII.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@startuml
actor Foo1
boundary Foo2
control Foo3
entity Foo4
database Foo5
collections Foo6
Foo1 -> Foo2 : To boundary
Foo1 -> Foo3 : To control
Foo1 -> Foo4 : To entity
Foo1 -> Foo5 : To database
Foo1 -> Foo6 : To collections
@enduml
                                                               ,.-^^-._
 ,-.                                                          |-.____.-|
 `-'                                                          |        |
 /|\           |   ,-.                                        |        |
  |            +--{   )        ,----.          ,----.         |        |       ,----.
 / \           |   `-'         |Foo3|          |Foo4|         '-.____.-'       |Foo6|
Foo1            Foo2           `----'          `----'           Foo5           `----'
 |  To boundary  |               |               |               |               |
 | -------------->               |               |               |               |
 |               |               |               |               |               |
 |           To control          |               |               |               |
 | ------------------------------>               |               |               |
 |               |               |               |               |               |
 |               |   To entity   |               |               |               |
 | ---------------------------------------------->               |               |
 |               |               |               |               |               |
 |               |          To database          |               |               |
 | -------------------------------------------------------------->               |
 |               |               |               |               |               |
 |               |               | To collections|               |               |
 | ------------------------------------------------------------------------------>
Foo1            Foo2           ,----.          ,----.           Foo5           ,----.
 ,-.           |   ,-.         |Foo3|          |Foo4|          ,.-^^-._        |Foo6|
 `-'           +--{   )        `----'          `----'         |-.____.-|       `----'
 /|\           |   `-'                                        |        |
  |                                                           |        |
 / \                                                          |        |
                                                              '-.____.-'

sequence diagram

This also worked in ASCII.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
@startuml

actor "Utilisateur"

"Utilisateur"-> "Système: Demande de l'historique"
"Utilisateur"<-- "Système: Liste des fichiers"
"Utilisateur"-> "Système: Sélectionner un ou plusieurs\nfichier(s) et vérifier les URLs"
"Utilisateur"<-- "Système: Liste des URLs invalides\ndu/des fichier(s) sélectionné(s)"

@enduml

state diagram

I’m not sure why this isn’t working currently.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
@startuml

title Message/Job Queue + Workers State Chart

state "Idle Queue" as Idle
[*] -> Idle
Idle -> Queue : Task Arrives
Queue : Task placed in queue.
Queue -> Worker : Worker collects Task
Worker -> ProcessingTask

state ProcessingTask {
  [*] --> long1
  long1 --> ProcessData : Enough Data
}

ProcessingTask -> [*]

@enduml
java.lang.IllegalArgumentException
	at net.sourceforge.plantuml.posimo.Path.<init>(Path.java:52)
	at net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramTxtMaker.<init>(CucaDiagramTxtMaker.java:113)
	at net.sourceforge.plantuml.cucadiagram.CucaDiagram.createFilesTxt(CucaDiagram.java:675)
	at net.sourceforge.plantuml.cucadiagram.CucaDiagram.exportDiagramInternal(CucaDiagram.java:625)
	at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:201)
	at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:135)
	at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:158)
	at net.sourceforge.plantuml.Pipe.managePipe(Pipe.java:113)
	at net.sourceforge.plantuml.Run.managePipe(Run.java:358)
	at net.sourceforge.plantuml.Run.main(Run.java:165)

sequence diagram

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@startuml

participant "app: Application" as app
participant "cm: ContentManager" as cm
participant "item: DownloadItem" as item

activate app
activate cm

note over app: User enters media info page

note over app: Check if item exists
app->cm: findItem(itemId)
cm->cm: lookup(itemId)

alt item found
    cm-->app: item
else not found
    cm-->app: null
    app->cm: createItem(itemId, contentURL)
    cm->item: new(itemId, contentURL)
    activate item
    cm-->app: item

    app->cm: loadMetadata()
    note over cm
        Download and parse manifest, save in db
    end note
    cm-->app: onTracksAvailable
    cm-->app: onDownloadMetadata
    note over app: * See //track-selection// flow
end group

note over app: app is ready to start downloading
app->item: startDownload()


@enduml
               ,----------------.                ,------------------.          ,------------------.
               |app: Application|                |cm: ContentManager|          |item: DownloadItem|
               `-------+--------'                `--------+---------'          `--------+---------'
         ,---------------------------!.                  ,-.                            |
         |User enters media info page|_\                 |X|                            |
         `-----------------------------'                 |X|                            |
            ,--------------------!.                      |X|                            |
            |Check if item exists|_\                     |X|                            |
            `----------------------'                     |X|                            |
                      |X|        findItem(itemId)        |X|                            |
                      |X| ------------------------------>|X|                            |
                      |X|                                |X|                            |
                      |X|                                |X|----.                       |
                      |X|                                |X|    | lookup(itemId)        |
                      |X|                                |X|<---'                       |
                      |X|                                |X|                            |
                      |X|                                |X|                            |
____________________________________________________________________________________________________________
! ALT  /  item found  |X|                                |X|                            |                   !
!_____/               |X|                                |X|                            |                   !
!                     |X|              item              |X|                            |                   !
!                     |X| <- - - - - - - - - - - - - - - |X|                            |                   !
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!
! [not found]         |X|                                |X|                            |                   !
!                     |X|              null              |X|                            |                   !
!                     |X| <- - - - - - - - - - - - - - - |X|                            |                   !
!                     |X|                                |X|                            |                   !
!                     |X| createItem(itemId, contentURL) |X|                            |                   !
!                     |X| ------------------------------>|X|                            |                   !
!                     |X|                                |X|                            |                   !
!                     |X|                                |X|  new(itemId, contentURL)  ,-.                  !
!                     |X|                                |X| ------------------------->|X|                  !
!                     |X|                                |X|                           |X|                  !
!                     |X|              item              |X|                           |X|                  !
!                     |X| <- - - - - - - - - - - - - - - |X|                           |X|                  !
!                     |X|                                |X|                           |X|                  !
!                     |X|         loadMetadata()         |X|                           |X|                  !
!                     |X| ------------------------------>|X|                           |X|                  !
!                     |X|                                |X|                           |X|                  !
!                     |X|             ,---------------------------------------!.       |X|                  !
!                     |X|             |Download and parse manifest, save in db|_\      |X|                  !
!                     |X|             `-----------------------------------------'      |X|                  !
!                     |X|       onTracksAvailable        |X|                           |X|                  !
!                     |X| <- - - - - - - - - - - - - - - |X|                           |X|                  !
!                     |X|                                |X|                           |X|                  !
!                     |X|       onDownloadMetadata       |X|                           |X|                  !
!                     |X| <- - - - - - - - - - - - - - - |X|                           |X|                  !
!                     |X|                                |X|                           |X|                  !
!      ,------------------------------!.                 |X|                           |X|                  !
!      |* See //track-selection// flow|_\                |X|                           |X|                  !
!~~~~~~`--------------------------------'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!
                      |X|                                |X|                           |X|
      ,---------------------------------!.               |X|                           |X|
      |app is ready to start downloading|_\              |X|                           |X|
      `-----------------------------------'              |X|                           |X|
                      |X|                       startDownload()                        |X|
                      |X| ------------------------------------------------------------>|X|
               ,------|X|-------.                ,-------|X|--------.          ,-------|X|--------.
               |app: A|X|ication|                |cm: Con|X|tManager|          |item: D|X|loadItem|
               `------|X|-------'                `-------|X|--------'          `-------|X|--------'
                      `-'                                `-'                           `-'

component diagram

Component diagrams are better in SVG. ASCII can’t do things like grouping and different types of links.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@startuml

/'
 ' skinparam component {
 '     FontColor          black
 '     AttributeFontColor black
 '     FontSize           17
 '     AttributeFontSize  15
 '     AttributeFontname  Droid Sans Mono
 '     BackgroundColor    #6A9EFF
 '     BorderColor        black
 '     ArrowColor         #222266
 ' }
 '/

title "OSCIED Charms Relations (Simple)"

/'
 ' skinparam componentStyle uml2
 '/

cloud {
    interface "JuJu" as juju
    interface "API" as api
    interface "Storage" as storage
    interface "Transform" as transform
    interface "Publisher" as publisher
    interface "Website" as website

    juju - [JuJu]

    website - [WebUI]
    [WebUI] .up.> juju
    [WebUI] .down.> storage
    [WebUI] .right.> api

    api - [Orchestra]
    transform - [Orchestra]
    publisher - [Orchestra]
    [Orchestra] .up.> juju
    [Orchestra] .down.> storage

    [Transform] .up.> juju
    [Transform] .down.> storage
    [Transform] ..> transform

    [Publisher] .up.> juju
    [Publisher] .down.> storage
    [Publisher] ..> publisher

    storage - [Storage]
    [Storage] .up.> juju
}

@enduml