p = 'crates/spt/src/cli.rs'
b = open(p, 'rb').read()


def sub(old, new, label):
    global b
    o = old.replace('\n', '\r\n').encode()
    n = new.replace('\n', '\r\n').encode()
    assert b.count(o) == 1, (label, b.count(o))
    b = b.replace(o, n)


# The complement doc's count.
sub("/// The complement of [`knock_remote_refusal_line`]'s three: between them the two",
    "/// The complement of [`knock_remote_refusal_line`]'s four: between them the two",
    'complement doc')

# The prose walk - the guard that RENDERS each line and would have caught my own
# collapsed continuation in KNOCK_PEER_SILENT.
sub('''            O::Unconfirmed { node: node.clone() },
        ];
        assert_eq!(sites.len(), 3, "every non-delivery outcome is walked");
''',
    '''            O::Unconfirmed { node: node.clone() },
            O::PeerSilent { node: node.clone() },
        ];
        assert_eq!(sites.len(), 4, "every non-delivery outcome is walked");
''', 'prose walk')

sub('''        // And the walk covers only refusals: an outcome that is not one of the
        // three renders nothing here rather than a line nobody wrote.
''',
    '''        // And the walk covers only refusals: an outcome that is not one of the
        // four renders nothing here rather than a line nobody wrote.
''', 'prose walk tail')

sub('''    // instance), and its site list is PINNED so an enumeration that silently
    // shrank fails loudly rather than passing over an empty set.
''',
    '''    // instance), and its site list is PINNED so an enumeration that silently
    // shrank fails loudly rather than passing over an empty set.
    //
    // It earned its keep again in releases#289: `KNOCK_PEER_SILENT` was authored
    // with the same lost `\\` continuation, and this is the walk that renders it.
''', 'prose walk preamble')

# The partition walk.
sub('''            O::Unconfirmed { node: node.clone() },
            O::Local,
''',
    '''            O::Unconfirmed { node: node.clone() },
            O::PeerSilent { node: node.clone() },
            O::Local,
''', 'partition list')

sub('''        assert_eq!(
            every.len(),
            8,
''',
    '''        assert_eq!(
            every.len(),
            9,
''', 'partition len')

open(p, 'wb').write(b)
print('walks updated')
