-
Notifications
You must be signed in to change notification settings - Fork 3
/
toolkit.nu
114 lines (96 loc) · 3.52 KB
/
toolkit.nu
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use nu-history-tools/ [analyze-history aggregate-submissions]
def 'main' [] {}
def 'main update-examples' [] {
aggregate-submissions --quiet
| update freq_by_user {ansi strip}
| update importance {math round --precision 2}
| save -f ( [assets script_results_examples aggregated-submissions.csv] | path join )
analyze-history --quiet
| update freq_by_user {ansi strip}
| update freq_norm {math round --precision 2}
| update importance {math round --precision 2}
| save -f ( [assets script_results_examples nu-hist-stats-example.csv] | path join )
}
def 'main parse-crates' [
--output_dir: path = '/Users/user/git/nu-history-tools/assets/crates_parsing/' # A path to output `.csv` results
--crates_dir: path = '/Users/user/git/nushell/crates/' # A path to a Nushell's git repository
] {
# This script parses sources of nushell for the last x tags to extract nushell commands
if not ($output_dir | path exists) {
error make {msg: 'set an `$output_dir` param'}
}
if not ($crates_dir | path exists) {
error make {msg: 'set an `$crates_dir` param'}
}
let $out_csv_long = $output_dir | path join cmds_by_crates_and_tags_long.csv
let $out_csv_short = $output_dir | path join 'cmds_by_crates_and_tags.csv'
def parse_crates_from_tag [
tag?
] {
if $tag != null {
git checkout $tag
}
if $tag in ["0.2.0", "0.3.0", "0.4.0", "0_5_0", "0.6.0", "0.6.1"] {
cd ../src
}
rg 'PluginSignature::build\("(.*)"\)' -o -r '$1' | complete | get stdout
| append (rg 'fn name.*\n +"(.*)"' -U -o -r '$1' | complete | get stdout)
| append (rg 'expr_name!.*\n.*\n +"(.*)"' -U -o -r '$1' | complete | get stdout)
| append (rg 'expr_command!.*\n.*\n +"(.*)"' -U -o -r '$1' | complete | get stdout)
| append (rg 'lazy_command!.*\n.*\n +"(.*)"' -U -o -r '$1' | complete | get stdout)
| flatten
| lines
| parse "{path}:{name}"
| upsert crate {|i| $i.path | path split | get 0}
| reject path
| insert tag $tag
| str replace '0_5_0' '0.5.0' tag
| sort-by name crate
}
if not ($out_csv_long | path exists) {
$'name,crate,tag(char nl)'
| save -r $out_csv_long
}
let $parsed_tags = open $out_csv_long
| get tag
| uniq
| str replace '0.5.0' '0_5_0'
| append v0.96.0 # `v` was added by mistake so we ignore that tag
cd $crates_dir;
git checkout main;
git pull origin main;
mut $current_commit = (git rev-parse HEAD);
git tag
| lines
| where $it not-in $parsed_tags
| each {
|i| print -n $'(ansi yellow)parsing ($i) tag: (ansi reset)';
parse_crates_from_tag $i
}
| flatten
| sort -n
| to csv --noheaders
| save -ar ($out_csv_long);
git checkout $current_commit; # checkout back
cd -
let $cmds_agg = open $out_csv_long
| sort-by tag --natural
| group-by name
| values
| each {
|i| $i
| last
| rename -c {tag: last_tag}
| merge ($i | first | select tag | rename first_tag)
| move first_tag --before last_tag
}
| flatten
| sort-by -n last_tag first_tag crate name
let $cmds_missing = help commands
| where command_type in ['builtin' 'keyword']
| get name
| where $it not-in $cmds_agg.name
$cmds_agg
| save -f $out_csv_short
print $'($out_csv_short) file is saved'
}